Posts by rray • 66,288 points
1,220 posts
-
16
votes6
answers65532
viewsA: Sum in 2 inputs and appear in real time - Javascript
With pure javascript just take the values of the fields by id, with document.getElementById() convert the values to int using parseInt(), the number 10 means on which basis the number will be…
-
2
votes2
answers305
viewsA: How to model plots when you don’t know how many there are?
I believe that the most appropriate is to create a table with installments already paid, it depends a little on how your system is. Paid installments must have the fields, id_installment, payment…
-
2
votes2
answers104
viewsA: time() Function php
If you only want to use functions, strftime() and strtotime() also solve. echo strftime('%Y-%m-%d', strtotime('+2 weeks'));
-
1
votes3
answers744
viewsA: Split array and sort
The least bad way to sort the key-based array is to use usort() function cmp($a, $b) { return $a["ano"] < $b["ano"]; } $texto =…
-
4
votes1
answer890
viewsA: Pass data in php constructor to class
To pass value in the constructor, use the method __Construct(). class Elo{ public $name; public $sexo; public $mmr; public function __construct($nome, $sexo){ $this->name = $nome; $this->sexo…
-
15
votes4
answers5507
viewsA: Why are NULL values not selected?
null is no value, need to use IS NULL to know if the column has value or not. Are 3 values, something, empty and no value(null).
-
11
votes2
answers558
viewsA: What is the undescore "_" in the MYSQL LIKE?
The underscore (_) serves to compare any character only once, while the percentage (%) means any character in any quantity. (_) is equivalent to meta character (.) of regular expressions and (%) at…
-
1
votes1
answer760
viewsA: Set Default Value HTML form with PHP
To leave a selected option it is necessary to compare the id of the record that will be updated with the list of options (operator) and add in the tag <select> the attribute…
-
8
votes3
answers22400
viewsA: What is the difference between bindParam and bindValue?
In the bindParam() the expected argument is a reference(variable or constant) cannot be a primitive type like a string or loose number, function/method return. bindValue() can receive references and…
-
1
votes3
answers1861
viewsA: C# MVC Run Function (Logout) When Closing Browser
There is no 100% reliable way to do this as on a desktop system, an alternative in the web environment is to use the event unload() that desexib the page, with some filters is close to the desired.…
-
1
votes2
answers233
viewsA: How do I display the customer name of a particular sale? I’m not getting the name with get
The problem seems to be your table venda the fields cliente and produto are not descriptions like john and coffee, are ids so when calling getCliente() a number is displayed. To fix this it is…
-
6
votes5
answers2497
viewsA: What is the purpose of the "Spaceship Operator" <=> of PHP7?
From one version here, php seems to be trading some functions for operators. For example, Pow() that makes the exponentiation calculation can be exchanged for (**); func_get_args() can be exchanged…
-
10
votes3
answers887
viewsA: How to print a constant in the middle of a string, without concatenating?
You can use the function printf() to print a formatted string and then pass the values to barter or use a comma in that case. define('NOME_USUARIO', 'lol'); echo 'meu nome é ', NOME_USUARIO;…
-
0
votes2
answers32
viewsA: Problems saving information to a database column
Missing specify the column name as the new value and which is the condition column. change: UPDATE jogador SET $pont WHERE cmbjogador To UPDATE jogador SET pontuacao = $pont WHERE id = $id Don’t…
-
0
votes1
answer804
viewsA: Store all array positions in a variable?
implode(), transforms an array into a string, the function accepts two arguments the first is the delimiter which sepera the array items, the second is the array. If only one argument(array) is…
-
1
votes1
answer280
viewsA: Mysql - check occurrence in all fields
If it is possible to use a programming language, this task is not so complicated. The idea is to make two queries first by picking all the fields of a given table (maybe the type matters), then in…
-
0
votes3
answers90
viewsA: Insert picture into 2 different tables
Who has the method lastInserId() is class PDO and not the Pdostatement, in that case change $inserir for $con. Change: $last = $inserir->lastInserId(); For: $last = $con->lastInserId(); It…
-
3
votes1
answer63
viewsA: Only the last array item is displayed
Place the code snippet <div id="comments"><?php echo $xmlpath; ?></div> while inside so will be printed all comments and not only the last. while($row = mysql_fetch_array($cmd_q))…
-
0
votes2
answers31
viewsA: Help Sintx error
You can not do this type initialization in the property, if you need to define a dynamic default value I do in the constructor. Replace the var that was used in php4 by one of three available…
-
5
votes2
answers604
viewsA: Ternary Operator, is_array, unexpected
PHP is interpreting its expression as true, because string is not empty(true) is evaluated as true and concatenated with something (return of is_array()) that makes no difference, see in the second…
-
4
votes2
answers933
viewsA: codeigniter error 3: Undefined variable: alert
$alerta does not exist in the view because in that if, the key name in $dados will be defined from the array denifining, the Alert key does not find, as the only one defined was class…
-
3
votes1
answer61
viewsA: problems when sending data to the database
The problem is that the variables defined are in minuscules and the passings in the uppercase Insert, php is case sensitive for variables, so $nome is different from $NOME. The name of the super…
-
4
votes1
answer145
viewsA: Array returns only item 0 PHP
It is possible to simplify the code, to prevent the header and its values, using the FETCH_NUM and one more forech that will print each value in the right column. if($consUsu->execute()){…
-
0
votes3
answers233
viewsA: Convert the date format the user types
If you are using postgres, you can format the date at any time even in an Internet, other than mysql. Before the main query this line will convert all fields dates of YYYY-MM-DD for DD/MM/YYYY at…
-
1
votes3
answers6345
viewsA: In PHP, what is the best way to print a variable through a function?
It depends on the case, if you just print the value you have no reason to assign to a variable. Just echo $this->teste(). If the return of the method is used later for a calculation or other…
-
2
votes2
answers202
viewsA: How to Exchange Arrays query for Selects query in Mysql
By the example shown, I believe that just do the assignment in the array and return it at the end of the function, thus: ctype_digit() checks whether $id_marca is integer otherwise returns an empty…
-
2
votes1
answer901
viewsA: CI3 Does Not Load the model on the umbler server
In codeIgniter 3 the first letter of the class name must be uppercase, the other lowercase and the file name must be equal to the class name, this rule is applied to controllers as well. Classe…
-
3
votes1
answer89
viewsA: Database does not show the data entered by the user
Text fields should be between single quotes each, always add mysql_error() to get the error message from the bank. $titulo = mysql_real_escape_string($_POST['titulo']); $campo =…
-
5
votes4
answers2514
viewsA: Is there a difference between the is_file and file_exists function?
Yes there are some differences: file_exists() checks whether the directory or file exists, passed as argument. is_file() The definition of the manual is Tells whether the Given file is a regular…
-
4
votes4
answers6626
viewsA: What SQL command shows the maximum number of active connections to the Mysql database?
Another option to display connections is: SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST
-
2
votes3
answers767
viewsA: Netbeans IDE: Warning Message
It seems that netbeans has some tool that checks the code, in which case it suggests that the method has 20 lines at most, other options may be checkspelling, minimum size in variable names etc.…
-
12
votes2
answers2324
viewsA: Why do they say using arroba to suppress errors is bad practice?
Hiding error messages/warnings creates subtle and difficult-to-detect problems, not to mention that the use of arroba is inline, then if need remove will have to be done instruction by instruction.…
-
4
votes3
answers218
viewsA: What makes the expression "'2 pigs' + '3 horses' == '5 animals'" return true in PHP?
PHP always casts the values for booleans by default, so in some instructions where you believe you are comparing numbers for example, PHP is comparing booleans. Two important things are the order of…
-
5
votes3
answers49921
viewsA: Convert string number to PHP integer
settype returns whether the variable type has been successfully changed(true or 1), null or 0 to failure. You can cast to int. <?php $variavel = (int) '200'; echo gettype($variavel)…
-
2
votes3
answers524
viewsA: Count without using rowCount from PDO
In your method returns only $sql and not the results (fetchAll(). public function read($table, $fields, $where = null, $fetchMode = PDO::FETCH_ASSOC) { $where = isset($where) ? "WHERE {$where}" :…
-
6
votes1
answer137
viewsA: Doubt about PHP function 'end'
Just like that, the parentheses at the beginning and at the end do nothing! $extensao = ( end ( explode ('.', $_FILES [ "img" ][ "name"] ) ) ) ; -----------^ ^---- The small problem of this code is…
-
4
votes2
answers733
viewsA: How to make a full date common?
One way to solve this is to replace the month me portugues by in English through an array with the help of str_replace(). <?php $en = ['','January', 'February', 'March', 'April', 'May', 'June',…
-
0
votes4
answers364
viewsA: Error saving form data in php
To know the error returned from the database use the function mysql_error(), by sql seems to be a syntax error, missing a comma(,) in the call of the penultimate field. INSERT INTO ... deficiencia…
-
7
votes1
answer174
viewsA: Add data to a Mysql table with PHP. What’s wrong?
And once again the code was correct, the problem was the autocommit deactivated. When it is off you are required to tell the database that that command (an Insert/update/delete DML) must be executed…
-
1
votes1
answer169
viewsA: how to use foreach
It seems that the variables are not receiving the correct values, check whether mysql_query() did not return error, after that do mysql_fetch_array($query) in a while and print the products if you…
-
22
votes2
answers766
viewsA: How to humanize a date in PHP
I know two libraries to make this conversion, one is the Carbon which is a specialization of the default php Datetime and the PHP Humanizer humanizing dates and other information the limitation of…
-
20
votes2
answers766
viewsQ: How to humanize a date in PHP
How to humanize a date in PHP? For example, from that date 2015-08-20, I want the function to return to me Há uma semana, because it’s strange to read something like foi publicado há 754 dias or…
-
9
votes3
answers2715
viewsA: Is there any way to display the size of the string in a MYSQL result?
To know the number of characters you can use char_lenght() in the example returns 4 because the return is based on the characters and not on the bytes as it does lenght() that returns 6(number of…
-
1
votes1
answer4734
viewsA: SQLSTATE[HY093]: Invalid Parameter number: Parameter was not defined
SQLSTATE[HY093]: Invalid Parameter number: Parameter was not defined Now the error has changed if compared to the first version of the question. When using named placeholder(:valor) the array passed…
-
1
votes4
answers1466
viewsA: How best to pass values to attributes
The best way is the one that fits the situation :). Arguments passed in constructr has the advantage of already initializing one or more dependents of the created object, this ensures that attribute…
-
8
votes3
answers2129
viewsA: What is the simplest way to create a mask for numbers in PHP?
One way to solve this is to combine str_pad() to fill the left zeros* if the string is less than 8 characters long, chunk_split() to insert the hyphen every 4 characters and the Trim() to remove the…
-
1
votes2
answers114
viewsA: Insert Mysql PDO
SQLSTATE[HY093]: Invalid Parameter number: number of bound variables does not match number of tokens in It means that in Insert there are more columns specified than values, in case you have a bind…
-
2
votes3
answers2837
viewsA: Store multiple checkboxes in a single column with PHP + Mysql
The simplest exeplo is to first transform checkboxs into an array, adding []brackets in attribute name, then check if there is any value in $_POST['genero'] if there is make a implode() to turn the…
-
5
votes2
answers6065
viewsA: Counting lines reached PDO
Use the method rowCount() it returns the lines affected by a DML(Insert, update delete) in some databases also returns the rows of a select, in mysql it works correctly. $linhas…
-
2
votes6
answers392
viewsA: How to make a explode without returning empty values?
You can also get the same result with the function Strtok() <?php $str = "//pagina//id/1//"; $item = strtok($str,'/'); $arr[] = $item; while($item = strtok('/')){ $arr[] = $item; } echo…