Posts by rray • 66,288 points
1,220 posts
-
2
votes1
answer100
viewsA: Capture only one element of an array
Can use array_map() to modify/reorganize the output array and array_column() to capture key data produto_id at once. The keyword use imports the variable $produtos for the scope of the anonymous…
-
1
votes2
answers1017
viewsA: Multiple insert with php PDO and Mysql
With these chained foreachs what happens is for element in $nome the second foreach runs and only then comes back the first one which basically combines all the values. For example if each array has…
-
2
votes2
answers37
viewsA: while Inside the variable
First close the string, it is not possible to concatenate it with a repeat loop. Use a while whether to use the do-while in the case of the empty return query some Undefined index will be generated…
-
2
votes1
answer415
viewsA: View data display with Codeigniter
The problem is in get_titles() you ask to return an array containing other arrays and not an array of objects. The way to access an array is different from accessing an object so the error in the…
-
2
votes3
answers840
viewsA: How to obfuscate a PHP email by filling part of the characters before @ (arroba) with * (asterisk)?
Can use sub_str_replace() to start where and how many characters to replace and str_repeat() to generate the string that replaces the original email. function ofuscaEmail($email, $inicio, $qtd){…
-
3
votes1
answer86
viewsA: How to convert html text (entities) to "normal" text?
Use the function html_entity_decode() to convert the html entities into the repective characters. echo html_entity_decode('responsável'); Exit: responsável…
-
2
votes1
answer628
viewsA: Fatal error Uncaught Pdoexception: General error: mode must be an integer
The method query() do PDO does not support Prepared statements. When passing placeholders to Insert they will be understood as strings. To use Prepared statements the first step is to call the…
-
4
votes2
answers1940
viewsA: Add a number in front of all records
Use the function concat() to add zero to the left. SELECT concat(0, contrato) FROM tabela Example - sqlfiddle Related: Use CONCAT to adjust the amount of php mysql numbers…
-
1
votes1
answer26
viewsA: Validation of a field in a REGEX form
You can mount the regex in two parts, the first one specifying that the first character should be a lower-case letter (^[a-z]+) and the second that the rest can be both numbers and letters.…
-
3
votes3
answers65
viewsA: PHP - using isset and Gets
The isset() is not a function is a language Construct, it has a differential which is to pass N input arguments. Thus validation is done on all arguments if one of them is not valid isset() returns…
-
2
votes1
answer628
viewsA: Capturing the input type date
When searching for a non-existent id it returns Undefined. Add the id attribute with its name. <input type="date" class="form-control" name="data" id="data"> You can search for elements by…
-
3
votes3
answers1135
viewsA: How to make the first two numbers of a sequence Math.Andom are NOT EQUAL
I believe that the most appropriate way for this problem (not to repeat elements) is to use the set-type javascript because it does not allow duplicated elements. This simplifies both the number…
-
2
votes3
answers1183
viewsA: Ajax only returns if I put an "echo" instead of "Return" in php
To communicate from PHP to javascript you need to do it through a text output (echo/print) or other functions (remember http is a text-based protocol). The most correct is to leave the Return at the…
-
4
votes3
answers2102
viewsA: What is the difference between function and array assignment?
The elements added with array_push() have only their numeric indices only. In the form of assignment it can be both numeric and associative. $arr = array('e1' => 1, 'e2' => 2);…
-
1
votes2
answers337
viewsA: What is the Function of Error_reporting(0)
error_reporting() sets what types of errors will be displayed, this includes warnings, build errors, syntax etc. When setting zero it is interpreted to be false or will not display any errors when…
-
1
votes1
answer921
viewsA: Return Json in Array instead of object
If it is not possible to change the method select() to return an array without zero index this happens when if the method fetchAll() is used, the solution is to exchange it for fetch() Another way…
-
2
votes1
answer266
viewsA: ternary or if and Else condition with PHP
In this example it is the same thing. Whenever performing a single action the ternary is a good candidate in place of the if/Else. If you have more instructions to execute you will need the…
-
1
votes1
answer68
viewsA: I can’t do Insert in object orientation
Error happens because there is no method setNome() or setAlgo() in class ServiceUserInterno. This class has two dependencies to the first object of Mysqli and the second object User see in the…
-
11
votes3
answers1617
viewsA: Set value 0 when the number is negative
Set your column to unsigned (no sign) this ensures that only positive values zero and null are valid entries. In this example the first Insert already returns the error: Data truncation: Out of…
-
2
votes2
answers1276
viewsA: Undefined variable in PHP
The variable $raio does not exist at all. What is defined in your class is a property that has a different scope than a local variable. Your call always refers to the object ($this) or the…
-
0
votes3
answers349
viewsA: Mysqli + num_rows after a table query
Who has the return information of query lines is Resource and not the connection. Change: $linha = $conexao->num_rows($resultado); To: $linha = $resultado->num_rows;…
-
0
votes1
answer3628
viewsA: Recoverable error fatal error: Object of class mysqli_result could not be converted to string
You missed processing the query and extracting the result. You cannot pass a resouce directly into a string you need to extract the result first with the function mysqli_fetch_assoc() it returns an…
-
1
votes2
answers129
viewsA: Name as number in Array foreach
Since in this ifs you are only making simple assignments, you can exchange this approach for an array, then just access the correct Indice and already assign the respective value. $status = array(1…
-
1
votes1
answer1730
viewsA: How to tab a PHP echo?
If you are going to display this query in the browser put it in the tag <pre> and use the \t to specify a tab in the string. You can specify if you want this formatting with an add parameter…
-
1
votes1
answer181
viewsA: Automating deploy using Msbuild
An alternative with powershell is to request the input value to add the argument -AsSecureString. Testing on ISE will open an input box but as a script the characters will be replaced by asterisks.…
-
2
votes1
answer22
viewsA: How to mount a string with each item of an array that can have 1 value or multiple values?
If it’s just to format use the function implode() it converges a string array separating the elements by a delimiter in this case the comma. $pedido1 = array ('ketchup', 'mustard', 'barbecue',…
-
1
votes3
answers232
viewsA: Filter array value
Another way to solve this problem is to combine in_array() to know whether cnpj already exists in the array or not. To make the comparison correctly use array_column() this function extracts all…
-
5
votes3
answers1317
viewsA: Remove duplicate values from an array - php
If you just want to take the elements of the unrepeated array use the function array_count_values() it returns an array where the key is the input array values and the values are the amount found.…
-
2
votes2
answers2759
viewsA: How to make Regex accept only numbers?
Can use ctype_digit() to check if string contains only numbers. is_numeric() accepts fractionated numbers, negatives and plus sign. var_dump(is_numeric(-1.33)); //true var_dump(is_numeric(+1.33));…
-
2
votes2
answers48
viewsA: Error Insert mysqli
If you want to include a new record with alternative syntax Mysql should specify the column and its value, according to the code below. $query = "INSERT INTO tbl_image SET image_album = '$img_album'…
-
0
votes2
answers892
viewsA: PDO - Which is better: columnCount or rowCount?
rowCount() and columnCount() have purposes. rowCount() returns the number of rows affected by an INSERT/UPDATE/DELETE which is the equivalent of mysqli_affected_rows(). As PDO supports multiple…
-
2
votes3
answers7570
viewsA: Read PHP Multidimensional Array
In foreach use the syntax $key => $value This will return the reflective key name and value. change: foreach ($Array as $row) To: foreach ($Array as $chave => $row)…
-
1
votes1
answer473
viewsA: By clicking the.sql file it goes to Mysql Workbench
Every file in the eclipse is linked to a text editor (some Highlight in specific). You can configure this through the menu: Window>preferences. In threeview the left go in…
spring-bootanswered rray 66,288 -
1
votes2
answers1281
viewsA: How to check if there is a string in this array?
Use array_map() to extract the value of the object return an array with only the value, then you can directly compare the in_array() $plainArray = array_map(function($item){ return $item->date;}…
-
3
votes2
answers1254
views -
1
votes1
answer1500
viewsA: How to use mysqli_fetch_all in PHP correctly?
fetch_all() by default returns an array with numeric indices as shows the print_r() question. If you want that array returned if an associative uses the constant MYSQLI_ASSOC in the function call.…
-
4
votes1
answer76
viewsA: Regex Custom Creation
You can use that expression: ^FKDOC\d{16}$. Means it will capture at the beginning of the string by FKDOC followed by 16 digits (0-9).
-
3
votes4
answers15459
viewsA: What is the difference between LIKE, IN and BETWEEN in Mysql?
LIKE: is used to do partial searches in text type fields (varhcar text etc) using wildcards % and _. IN: Compare a value against a fixed set or even with a subquery. BETWEEN: Compares a value…
-
6
votes5
answers2297
views -
0
votes1
answer70
viewsA: Is Data Warehouse Transaction Oriented or Query Oriented?
I found the first half-short fragment, it is worth remembering another important characteristic of DW that the data practically do not suffer (nor should) changes to not interfere in the result of…
-
0
votes1
answer67
views -
8
votes4
answers2054
viewsA: What can be considered a character?
What can be considered as a character in the programming? Character is a visible symbol or not. There is difference between character and alphanumeric character? alphanumeric is a category…
language-independentanswered rray 66,288 -
1
votes1
answer921
viewsA: Codeigniter - Recover ID
Get methods must return the value of something and set save or assign a value to a class property. // setter ID private function set_negociacao_id($negociacao_id = null) { return $negociacao_id; }…
-
4
votes1
answer266
viewsA: Alternative String.replace()
Basically you need to exchange accented characters for not accented class Normalize looks like a good option she makes character decomposition based on UTF-8 code and this behavior varies according…
-
0
votes1
answer80
viewsA: How to maintain PHP checkbox data?
Just add the attribute checked input in this way is already marked when the page opens. Recommended reading: MDN - checkbox…
-
1
votes1
answer26
viewsA: How to return substrings in a delimited string?
You can use a regular expression to house the text inside the brackets with the function preg_match_all(). Since what matters is inside a group you must access the array returned in the Indice 1 and…
-
2
votes2
answers142
viewsA: How to delete a certain line of code warning?
When accessing $Key[$SrcPos] in some while iteration generates a Warning due to the value of $SrcPos do not match any array key, in such cases it is simpler and correct to use a isset() to address…
-
1
votes2
answers151
viewsA: Validation PHP numeric field
To validate whether input (string) contains only digits use the function ctype_digit(). You can simplify the logic by joining these variables into an array and then applying the function…
-
3
votes1
answer38
viewsA: How to turn a query row into columns and group according to the first 4 characters?
In the clasp GROUP BY use the function left() which returns the N characters left of the string, as a grouping criterion. SELECT * FROM tabela GROUP BY LEFT(PRODUCT, 4) Functional example -…
-
1
votes1
answer57
viewsA: Functions with same parameter
Create a flag telling which function should be executed the first step is to set this in javascript. $.getJSON('function_pro-1.php',{ codigo_produto: $(this).val(), executar: 1 //Código omitido In…