Posts by rray • 66,288 points
1,220 posts
-
1
votes1
answer809
viewsA: Capture Month in field date
Use the function Month() Mysql to compare only the month to the desired value. There are other functions to extract a piece of the date like year(), day() etc.. select month(now()) #retorna 11 or…
-
2
votes2
answers233
viewsA: After ajax action, data is not saved in mysql database
You should take php by the same names you sent by js, $_GET['latitude'] and $_GET['longitude'] data: "latitude="+$tlati+"&longitude="+$tlong+"&acao=btn_finaliza change to: $latitude =…
-
1
votes1
answer23
viewsA: Insert function is not working
$insereDados doesn’t seem to have a property called pdo nor the connection, who receives the connection is the variable $pdo she’s the one to call prepare()…
-
4
votes2
answers1787
viewsA: Take multiple values from a multi select
To call all selected options just do $_POST['opcoes'], select name must have brackets and attribute multiple to function properly. <form method="post" action="#"> <select id="opcoes"…
-
3
votes1
answer629
viewsA: Format date from variable with php
Convert that date by to timestamp with strtotime() and then take the desired format with date() echo date('d/m/Y', strtotime('Sun Jan 10 00:00:00 CST 2016')); Example - 3v4l…
-
4
votes4
answers814
viewsA: Repeat alphabet similar to excel columns
You can increment a string by its ASCII value in php as long as it is in the valid interval of (65..90 A..Z, 97..122 a..z) so`range('A', 'Z') works, here you have it more detailed explanation. You…
-
0
votes1
answer133
viewsA: Save data to DB and recover ID automatically
@@IDENTITY is used by SQL Server and not by Mysql pstmAux = conn.getConnection().prepareStatement("SELECT @@IDENTITY"); To recover the id of records inserted in Mysql use LAST_INSERT_ID() pstmAux =…
-
4
votes3
answers221
viewsA: Error: the right syntax to use near 'add
The problem is add is a mysql reserved word then it is necessary to escape column names or tables with backsticks. The add is usually seen this way: ALTER TABLE <nome> ADD COLUMN <nome>…
-
3
votes3
answers717
viewsA: How to add a PHP variable only if it is set?
PHP cast for Boolean virtually the time or expression is summing the results of isset() which may be 1 or 0. <?php $var = 5; $var2 = 4; $total = isset($var) + isset($var2) + isset($var3); echo…
-
1
votes1
answer1304
viewsA: How to manipulate data from the database using PDO
It is not difficult to convert the code: $sql = "SELECT valor FROM entrada WHERE id_empresa = :id ORDER BY data DESC"; $stmt = $pdo->prepare($sql); if($stmt->execute(array(':id' => $id))){…
-
2
votes2
answers3935
viewsA: Grab user id by SESSION
The problem seems to be access to session, by the comments it was seen that the return of login() model return an object and played it in session it should be accessed so $_SESSION['login']->id.…
-
3
votes3
answers2431
viewsA: Fizzbuzz test in Javascript
Numbers that are not multiples of 3 or 5 are not printed because they are inside the first if and there is no console.log for them. if ((n % 3) == 0 || (n % 5) == 0) { } else { console.log(n); }…
javascriptanswered rray 66,288 -
1
votes1
answer2797
viewsA: What is the difference between Service and Application Software?
Service: usually a software that runs in the background and performs specific tasks, may or may not have some kind of interface either via command line or Gui. A service does not require much user…
-
1
votes2
answers491
viewsA: I cannot create php class and use PDO connection
function pegaDataConta(){ $pdo = conectar(); $pegaData=$pdo->prepare("SELECT data FROM entrada WHERE id_entrada:id"); $pegaData->bindValue(":id", 30); $pegaData->execute(); } Do not forget…
-
0
votes2
answers219
viewsA: Error using $this in static function
In your example, there is a static method that attempts to access an attribute of an instance(object) at some point was creating the object? not soon $this->algo will not be accessible.…
-
0
votes1
answer170
views -
0
votes3
answers1011
viewsA: Read a txt file by php and mysql and viewed by each user
Can save each column in the database make one explode() by pipe, if not too many lines can use file() to open the file as an array. <?php $linhas = file('gastos');//abre o arquivo como um array…
-
6
votes3
answers94
viewsA: How to stick with just one part of the string?
Can replace with a regular expression, which matches -[0-9], use the function preg_replace() for that reason. If the string is only idPergunta-18, utilize strstr() and inform the third…
-
1
votes2
answers998
viewsA: Use HTML div and store it as a variable
Use javascript to grab the div id and send it by ajax. This example uses jquery, don’t forget to add it to your test/project <!DOCTYPE html> <html> <script type="text/javascript"…
-
1
votes2
answers70
viewsA: Syntax error when using UNION
You have an error in your SQL syntax near 'FROM pedido a, tipofornecimento b ' at line 7 (SELECT a.id, a.cliente_id, a.arquiteto_id, a.vendedor_id, b.nome as tipofornecimento, <------- virgula a…
-
2
votes3
answers1036
viewsA: Grab last key from auto increment PDO
The two less bad exits to this problem, which I see are: 1) Create a column called excluido or ativo can be bit or Boolean, instead of deleting the record, update this column, this partially solves…
-
8
votes1
answer2550
viewsA: Capitalize string with accented characters
ucwords() is one of php’s string manipulation functions that does not support multibyte so it cannot convert accented characters or other languages. For each function that handles string there is a…
-
1
votes1
answer8914
viewsA: pass variables from AJAX to PHP
You need to set the sent parameters, in which case add quotes names to be identifiable in php. data: { 'idUsuario': idUsuario, 'idEscolha': idEscolha, } If left as below php will receive the post…
-
8
votes2
answers5038
viewsA: What is the difference between "/*" and "/**" comments in PHP?
/* Comentário 1 */, is a comment anyway with // or #. It is curious to comment that no kind of comment cancels the closing tagline ?> /** Comentário 2 */, is called doclet whatever is inside it,…
-
3
votes1
answer209
viewsA: How to construct the regular expression for the case?
I believe this regex serves to capture the desired pattern: ^\d([\w\-/]*) It means, the first character must be a number, followed by a group containing a list of caracateres a-za-Z0-9_-/…
-
0
votes1
answer77
viewsA: PHP MS Sql query script for My Sql
You can do a mysql Insert for each mssql line this way: $sql = "SELECT c1, c2, c3, c4 FROM mssql_table"; $result = odbc_exec($conn, $sql); while($row = odbc_fetch_array($result)){ $insert =…
-
1
votes2
answers1052
viewsA: Select PHP in tables with special characters
The problem seems to be the incompatibility between Charsets base and code/client/file. When OP displays the error message: have an error in your SQL syntax; check the manual that Corresponds to…
-
2
votes1
answer438
viewsA: How do I handle data from a Date search in the Where clause in Postgres?
You can compare a piece of the date with the function Extract, the first argument is desired type and the second is the name of the field. SELECT ... WHERE data_emissao = '2015-10-23' SELECT ...…
-
10
votes5
answers1499
viewsA: What is a gluttonous regular expression?
A Regex with a sweet tooth (Greedy) try to match as many times as possible the specified pattern, use the asterisk to set this *. A non-greedy expression combines the text as little as possible, by…
-
3
votes2
answers766
viewsA: What is 1 for in regular expression, in javascript?
It is the result of the first group that is representing the ( ), then number bar (\1) get its value. Other languages use dollar sign, e.g.: $1. Regular expressions have utilities on the day, say…
-
1
votes1
answer85
viewsA: Error number 1064 Codeigniter
Table name not specified UPDATE tabela SET
-
3
votes1
answer3453
viewsA: Doubt about the error "Strict standards: Only variables should be passed by Reference in"
Yes it’s wrong, mysqli_stmt_bind_param expects the second(oo) or third(procedural) argument to be at all times a reference that means it must be a variable and not the return of a function/method or…
-
0
votes1
answer85
viewsA: Unlink: Permission Denied - Trying to get Property of non-object
while($r = $Pic) { unlink('../img/produtos/'.$r->nome); } $r receives $Pic, wouldn’t it be the same? where is the stopping condition? $Pic = $row_listaPic['nome'];, $r is an array and not an…
-
0
votes1
answer446
viewsA: Mysql UPDATE function is editing right, but creates a new empty row at the end of the table
Editing usually works this way, by clicking on the link of the listing page the user is redirected to the editar.php, in it is done database search by id, which was passed by $_GET. Listing.php $row…
-
11
votes4
answers3299
viewsA: Typing the return in PHP 7. What are the advantages?
The advantage of typing the return method, means that the promised will be fulfilled or your money back in the form of error or Exception. Currently in PHP5, what can happen is to pass a different…
-
2
votes2
answers579
viewsA: How to pass an array of php Stdclass objects to a JS variable using $.ajax() jquery
Take this array, send as a json to javascript <?php $arr = array(array('id' => 1 ), array('id' => 2 ), array('id' => 3 )); echo json_encode($arr); In javascript turn this string into a…
-
1
votes1
answer104
viewsA: Problem filtering counties by the district selected with ng-change in Angularjs?
To list the counties according to the district selected, it is necessary to add a WHERE to specify this. $sql = $conexao->prepare("SELECT * FROM concelhos WHERE id_distrito = :distritos ORDER BY…
-
60
votes3
answers21803
viewsQ: What is CGI and what is its purpose?
What is the CGI (common gateway interface) and what it does? It’s an ancient technology? Are there other alternatives to it? If so, which?
-
14
votes4
answers301
viewsA: How to find hashtags in a string and store them in an array?
I believe that this regex solves the problem, is made the initial combination of # followed by any character in the range of (a-z, 0-9), the parameters i means that the combination will be case…
-
6
votes6
answers16160
viewsA: Format 9 and 8 digit phone numbers
Check the amount of characters in the string if 10 needs to add the ninth digit of the opposite. <?php function formataTelefone($numero){ if(strlen($numero) == 10){ $novo =…
-
4
votes2
answers950
viewsA: How to create Exceptions to handle statement with Mysqli
The function that turns errors into exceptions in Mysqli is to use the function mysqli_report(). Since Mysqli is a specialized API, it has some interesting features, such as detecting common errors…
-
7
votes1
answer3509
viewsA: Select with Prepared statements Mysqli
When using Prepared staments with Mysqli in a select, you first need to pass the database result to php, this is done with the method/function get_result() the great advantage of it is that you do…
-
3
votes1
answer52
viewsA: Mysqli cannot return methods
The error happens because no database was selected, so the prepare() failed and does not return an object. In the method openDB(), add fourth argument in mysqli constructor $this -> db = new…
-
2
votes1
answer356
viewsA: Field date entering 0000-00-00 00:00:00
You can force a value to that date field by creating a property with the same column name. $data->estado = $_POST['estado']; $data->created = date('Y-m-d H:i:s');…
-
1
votes1
answer927
viewsA: Testing a condition before UPDATE, with PHP - Mysql
I believe it would be right to update the project only when an id is found and its status is 1. if($id){ $sqlstatus = "SELECT * FROM projetos WHERE COD_PROJETO = $id"; $resultadost =…
-
1
votes1
answer604
viewsA: Call to Undefined Function transliterator_transliterate() in php 5.512 using wampserver 2.5
The method transliterator_transliterate() belongs to the class Transliterator, which is part of the lntl. To enable it, open php.ini, search for the line, remove php.ini ; and restart the apache.…
-
3
votes2
answers1047
viewsA: Validation Numeric(12,2) Postgres
If you want to know if the given value is greater than the column limit, take the hint of the error, make 10 to the 10(10^10), play in a variable or constant and make comparisons. <?php…
-
3
votes1
answer1201
viewsA: Difference between varchar2 and nvarchar2
nvarchar2 stores the characters as Unicode and the Encode must be AL16UTF16 or UTF8. varchar2 stores characters according to other encodings other than those provided by nvarchar2. nvarchar2 swear2…
-
8
votes3
answers833
viewsA: With the ninth digit on the phones, how can I solve the problem of displaying 8-digit phones?
If all numbers are in this format, it is possible to use substr_replace() to add the 9 in the fifth position of the string. <?php $str = '(31)9915-2855'; $novo = substr_replace($str, '9', 5, 0);…
-
10
votes4
answers9913
viewsA: Difference between prepare() and query()?
prepare() uses Prepared statements a made query it is optimized by the database and can be executed N times what changes are the arguments, its use avoids problem with sql Injection since used…