Posts by rray • 66,288 points
1,220 posts
-
4
votes6
answers3209
viewsA: How to turn string into time in PHP?
You can use the combination of methods diff() which calculates the difference between the hours and format() to format the time as desired in the class Datetime. Datetime has existed since PHP 5.2,…
-
1
votes1
answer32
viewsA: Why does the Splstack class not serialize with the json_encode function?
In the case of the question example the return is empty because the added items are inside a property(dllist) private so it is not accessible to json_encode(). If an external function had access to…
-
0
votes2
answers198
views -
5
votes1
answer548
viewsA: 9 Type and Count Lines via Regex Notepad++
Notepad++/Column mode With Notepad++ you can solve this problem in three steps. 1 - Add the 9, place the courses in the third character of the first line and activate the Edit>column mode menu or…
-
4
votes3
answers3386
viewsA: Check if there is a character inside a text
Can use preg_split() creating an array based on a delimiter is a regular expression. [^\w@\.] It means combine anything other than letters([a-za-Z), numbers([0-9]) that is defined with \W, @ and \.…
-
11
votes2
answers220
viewsA: Meaning of append syntax
A new option is created with the text(description), which is contained in the variable city and is marked as selected selected option. { text: city, selected: "selected"}…
-
1
votes3
answers67
viewsA: Format buffer, php
Utilize json_encode() to have the expected exit: <?php $str = "<div>Espere, será exibido após o carregamento dos itens.</div>"; $json = json_encode($str); print_r($json); Exit:…
-
0
votes1
answer157
viewsA: Insert the result of a query into a php file
There are two syntax errors in this line, remove the int and the echo of the second argument. int file_put_contents ($filename, echo ''.$arquivo.'</a><br />'); -^ -----^ Right: Also…
-
1
votes3
answers358
viewsA: how to use date interval to count days?
You can take the product creation date and calculate the difference(compared to today) with diff() <?php $produto = new stdClass(); $produto->dataCriacao = new DateTime('2015-10-01'); $dias =…
-
7
votes3
answers31029
viewsA: What is a Servlet and what is it for?
Servlet is a java class for working with web development although it is not specially developed for this. In this class, the manipulations of the requisitions are made, two important members are the…
-
6
votes2
answers1125
viewsA: Sql - Delete Bulk Records - Delete Bulk
Truncate has better performace than a delete without Where because the first does not log the deleted lines while the second does it for each one. TRUNCATE table nome can be translated by the bank…
-
0
votes3
answers833
viewsA: Select works on the localhost but does not work on the server
By the demonstration of the code in question, it failed to do the fetch() so the print_r of $result displayed mysqli_result Object ( ) include 'conexao.php'; $sql = "SELECT * FROM `galeriafotos`…
-
5
votes3
answers17415
viewsA: Mysql field type change
Yes, this instruction will work and will keep the converted values, in case 1 to active and 0 to inactive. Another alternative is to create a new column and then perform the updates one by one.…
-
5
votes1
answer132
viewsA: How to return the Timezone timestamp set?
To get the timestamp converted with Timezone, add timestamp with offset (difference in greenwitch realation in seconds). Use methods getTimestamp() and getOffset() of the Datetime class. <?php…
-
0
votes2
answers206
viewsA: Mysqli multi_query INSERT + insert_id multiples tables autoincrement + Foreign key
To get consistent results use transactions, this ensures that only the data will be recorded if both Serts work. If the second Insert fails automatically the first will be canceled(rollback). For…
-
1
votes3
answers98
viewsA: Show BD value in Dropdown Box
Can simplify the check with the value that should have Selected with printf. <select name="nivel"> <?php foreach($niveis as $item){ $select = $item['id'] == $nivel_session ? $select =…
-
3
votes4
answers2294
viewsA: How to return an error after sending a form?
One option is to take the error message and pass it via get. Do not use the mysql_* functions they will be removed in php7. $sql = "UPDATE tabela set nome='algo' WHERE ID = $id"; $update =…
-
2
votes1
answer306
viewsA: Wscript http post/get in Jscript for PHP
In the powershell there is a specific cmdlet to create the Invoke-Webrequest is available from version 3. Example with get To send a simple request by simply: Invoke-WebRequest…
-
4
votes2
answers76
viewsA: Error passing variable as double parameter
To receive two or more arguments in function it is necessary to change your signature first. function pesquisaPagamentos($pesquisa){ for function pesquisaPagamentos($datainicio, $datafim){ The call…
-
12
votes3
answers3285
viewsA: What does -> mean in PHP?
(->) that operator is known informally as arrow, the manual calls him T_OBJECT_OPERATOR is used to access properties or methods of an object, for static members (those belonging/shared to the…
-
3
votes1
answer91
viewsA: My database is changing the last name by the registered name and no email appears
Variables in php are case sensitive, upper case are different minuscules, so: $nome is different from $Nome. The values sent by the form must be the same recovered by $_POST, <input type="text"…
-
1
votes1
answer1350
viewsA: How to go through all the records in the database table?
It seems simpler to check if the value already exists in the database than to use php for this. Add a WHERE comparing the desired value, if you have any return does not perform an Insert, if the…
-
7
votes3
answers2222
viewsA: What is a PHP Resource type? What is it for?
Resource is one of php’s types, it is used for various purposes like making database connections, opening/manipulating files or even working with streams. As the manual basically speaks the resorce…
-
3
votes1
answer46
viewsA: Doubt about Select
Use Prepared statements to define the values of your query, then send the query to the bank with executeQuery() and take the return and finally do a while to catch the results. String sql = "SELECT…
-
2
votes2
answers64
viewsA: 1054 - Unknow colunm in on clause
I believe that this way the query is correct, do not need to repeat the name in each INNER JOIN Unknow colunm 'planosclientes' in on clause. The error happens because the syntax says, join with the…
-
1
votes2
answers1031
viewsA: Pass external variable or Constant into a Function
Change the function signature by adding the new parameter and if you want to set a default value. function get_modelos($id_marca, $ptv=10) { Then just call: get_modelos($id_marca, 'van');…
-
1
votes2
answers612
viewsA: Doubt about white spaces within PHP code
Spaces or line breaks are interpreted by Mysqli as one of the placeholder types the error generated is: Number of Elements in type Definition string doesn’t match number of bind variables in Any…
-
1
votes2
answers824
viewsA: PDO connection does not give error, nor with dummy bank
The problem to be your dsn that is incorrect dbname:angularDB should be dbname=angularDB, the problem is that the connection failure does not throw an exception so it will never be sent to the catch…
-
14
votes3
answers823
viewsA: Can I have Javascript write PHP?
You cannot because javascript works on the client side of the http cycle and php works on the server side, so the code generated by javascript will never run on the server, it will only be a common…
-
9
votes2
answers357
viewsA: Portable blade and performance
The fact that Laravel has to convert Blade to valid PHP code, using regular expressions and the like, cannot result in a loss of performance? Loss of performace compared to what? template engines…
-
0
votes2
answers274
viewsA: Use ID generated from one FORM in another and UPDATE in bd
First make the function return the id inserted with a return $id. function saveimagem($name, $image) { //codigo omitido if($result){ echo "<br/>Foi feito o upload" ; $id =…
-
5
votes2
answers2838
viewsA: Write data to two tables from a PHP form
Utilize Prepared statements to avoid SQL Injection. Your question is a good example of how to use transactions and exceptions. If the first Insert work, will be written to the database. In case the…
-
14
votes6
answers10518
viewsA: Difference between php <?php tags and <?=
Yes, <?php is the most correct option to open the php tag, because the server is not always with open_short_tag enabled, usually what happens is the php code to be printed on the screen and not…
-
1
votes2
answers82
viewsA: I am unable to call user information
Fur comments and the error message Undefined index: username in, it was concluded that the problem was in the index.php file that was this way: index php. <?php require 'User.php'; echo 'Você é…
-
3
votes1
answer116
viewsA: Is it possible to validate id of a get without javascript?
When sending GET requests, parameters and values should be sent by the url, the attribute is useless id of html tags. Modify your link to: <a href="pagina.php?id=<?php echo…
-
2
votes1
answer45
viewsA: How to take the whole result of a for, and make it become a single variable
You can do this through a string, concatenating the values with .= or the numbers all come together. <?php $arr = range(1,6); $str = ''; foreach($arr as $item){ $str .= ' '.$item; } echo $str;…
-
13
votes3
answers17172
viewsA: How to pick up content within a string up to a "bar/" character
The function strstr(), breaks a string by a delimiter and returns the right part by default, by passing the third argument as true the return is the left part. $link = '13542345/essa_e_minhastring';…
-
3
votes2
answers109
viewsA: problems deleting file from unlink()
The problem is that end() expects a reference or is a variable do, the two-step assignment. Change: $image = end(explode('-',$_GET['photo'])); To: $nome = explode('-',$_GET['photo']) $ext =…
-
2
votes3
answers92
viewsA: Error in sql server
Compare the value with the column using trim() or its variants(ltrim() and rtrim()). SELECT * FROM tabela WHERE trim(campo) = trim(valor)…
-
1
votes1
answer156
viewsA: Bug in PDO? Table disappears after INSERT command, how to debug?
Part of the problem is the example of the question it does not simulate the symptom of the table disappear, already the github makes clear. TL;DR The method insert(), the select also, prepares the…
-
1
votes1
answer31
viewsA: I cannot print the array on the server
The way is to adapt the syntax of php to version 5.3, it is very simple, take the return of the function and call the key in count(). This functionality array and string literal Dereferencing, is…
-
0
votes1
answer170
viewsA: update PDO is not updating me
Use Prepared statements and treat the error if it occurs by checking the return of execute(), text fields and variants should be in simple quotes when making a query in the database, when using…
-
5
votes1
answer3509
viewsA: Error when using bindParam: Only variables should be passed by Reference
You cannot pass values or feedback from futions/methods to bindParam() because it expects references(variables) in this case just exchange for bindValue(). I see you’re riding a lib, bindParam()…
-
5
votes1
answer135
viewsA: error in mysql_result()
Use mysqli_fetch_assoc() or _array() to get the query return, do not mix themysql_ API with the new mysqli. $sql = "SELECT Sum(visitas) AS visitas FROM lp_post"; $visitas_total =…
-
4
votes5
answers2441
viewsA: How to concatenate String within a repeat loop?
If the variable is an array, and you want to delimit the elements by commas you can use only one implode(). echo implode(',', $valor);
-
4
votes3
answers3563
viewsA: mysqli_escape_string() expects Exactly 2 Parameters, 1 Given
When the mysqli functions are used the first argument is always the connection, this is what the error says. A documentationshow how the call should be: string mysqli_real_escape_string ( mysqli…
-
2
votes2
answers410
viewsA: How to make an SQL query that returns an object instead of an array?
With PDO you can transform each row returned from the bank using the constant PDO::FETCH_OBJ, a stdClass object will be created, its properties will have the same name as the database columns. $stmt…
-
3
votes1
answer122
viewsA: Find words in a string
You can use a regular expression, to capture only the characters between the brackets, the only detail is to escape them since they are metacharacters. The expression is \[.*\]/, means to capture a…
-
2
votes3
answers309
viewsA: Postgres SQLSTATE[42725]: Ambiguous Function
I managed to simulate the error and get the same SQL state 42725, by default the Standard uses emulated Prepared statements, what PDO driver does is to send all values as strings, so the error…
-
0
votes2
answers51
viewsA: Error registration report on method return
Return all rows after while do not need to create a new array, use an alias for the calculation. function cad_por_uf($uf,$dataInicial,$dataFinal, $conexao){ $consulta = "SELECT sum(cadastros) as…