Posts by rray • 66,288 points
1,220 posts
-
12
votes4
answers865
viewsA: Split a 16-digit number in PHP
You can break this string into equal parts with the function str_split() that returns an array. It is paired with explode() but instead of breaking the string by a delimiter str_split() does the…
-
1
votes1
answer587
views -
0
votes1
answer1527
viewsA: Warning: array_keys() expects Parameter 1 to be array, null Given in
The error says that an array was expected to put a null has been passed to function array_keys(). The beginning of the problem seems to be on this line: $campos = array('img_padrao' => $nomeImg,…
-
4
votes2
answers12279
viewsA: Complete number with zeros on the left with PHP
Use function str_pad() to add the zeros to the left and pass the fourth argument as STR_PAD_LEFT. echo str_pad(1, 4, 0, STR_PAD_LEFT); echo str_pad(10, 4, 0, STR_PAD_LEFT); echo str_pad(100, 4, 0,…
-
8
votes3
answers3280
viewsA: How can I make an Rand() that always generates only 4 random numbers?
It can generate a number with four digits informing the minimum and maximum arguments in the function call $presenca = rand(1000, 9999); If you want to show numbers smaller than 1000 use str_pad()…
-
4
votes4
answers882
viewsA: Update the data in the database without changing the others that already exist - PDO
You need to assign the array correctly, now you overwrite the string every if. Also missing to add simple quotes correctly at the time of implode()the ideal was to use Prepared statements and…
-
2
votes1
answer1026
viewsA: Call to a Member Function bind_param()
Could not bind a string, it should be done in the connection variable. First, it should be called prepare() $sql = "INSERT INTO…
-
1
votes1
answer265
viewsA: Encoding Eclipse -> Intellij
To change the file creation encounter on eclispe, I do the following steps: Menu Window>Preference. In treeview the sketch go to General>WorkSpace and change text file encoding for UTF-8.…
-
2
votes2
answers218
viewsA: Laravel/Eloquent - Undefined variable: idPedido
Needs to import' $idPedido into the anonymous function. Just as the named ones both have their own variable scope. This is done with keyword use in function: PedidoProduto::orwhere(function($query)…
-
0
votes1
answer657
viewsA: Codeigniter/Common.php and database/DB.php error
The & was used in PHP4 to create objects, this attribution construction became obsolete in PHP5. To solve the problem just remove it. Change: $objects[$class] =& instantiate_class(new…
-
3
votes2
answers454
viewsA: Inserting index and value into a two-dimensional array
You can do this by modifying the current iteration element with the & it changes/adds the variable value by reference or does not make a copy of the original. foreach($dados as &$d) {…
-
0
votes3
answers1389
viewsA: View array value in php
If your model returns only one record should use result_row() in place of result() that returns more than one and requires for/foreach. To access the value correctly in your view do:…
-
4
votes1
answer3317
viewsA: Error trying to migrate bd from Laravel to Postgresql
To enable the PDO extension for postgres in PHP, the first step is to find the following line in php.ini and remove the ; ;extension=php_pdo_pgsql.dll Then restart apache. You can check that the…
-
4
votes2
answers362
viewsA: Error in isset PHP
isset() not meant to be used with expressions, the documentation says what the purpose is. Determine if a variable is set and is not NULL. Translation: Determined if the variable is set and is not…
-
1
votes1
answer132
viewsA: Error in a Codeigniter library
The problem is on the line: if (end(array_keys($this->breadcrumbs)) == $key) { The function end() according to the documentation only accepts references as an argument, that is, only variables of…
-
3
votes1
answer343
viewsA: Error when using POST in Laravel API
Your code is correct and the error too :) $this->get('products' This route specifies that only requests through the get method will be processed otherwise it will be returned to http 405 method…
-
2
votes2
answers534
viewsA: View data in PHP table
There is no function in the library ibase_ returning the number of lines in a query. There are two options: the first via SQL is to execute the same query with a count(). The second way is to create…
-
0
votes1
answer3219
viewsA: Why the PDO error Uncaught Error: Call to Undefined method PDO::fetch()?
Code does not work because no Pdostatement is processed. prepare() returns one, so it is necessary to assign it to a variable. To send the query to is obligatory to call execute() and finally call…
-
1
votes1
answer160
viewsA: String validation (Isogram)
One solution is to use mb_convert_case() to correctly convert all accented characters correctly. preg_replace() is responsible for removing any character that is a letter or digit. preg_split() does…
-
4
votes1
answer413
viewsA: Error in passing value to View in codeigniter
It is common to pass more than one value to the view, in which case you should register the name that the variable will be accessible in the view the respective value, this is done through an array…
-
8
votes3
answers189
viewsA: How to properly make this condition?
if (isset($_POST['palavra']) === 'Andrêy Ferraz' || 'Andrêy' || 'Ferraz' || 'Andrey'){ It does not work as expected. The comparison made is if there is something in the string compares with true. It…
-
0
votes1
answer50
viewsA: Codeigniter like post and show as likes
To get all results of a query use result_array() or just result() (which returns an array of objects). row_array() return only one result/row from the database.…
-
0
votes2
answers563
viewsA: How to Put Caption Out of the Highcharts Chart
Inside the Y-axis add property opposite: true this will affect the values and the legend on the left to the right side. yAxis: { opposite: true, title: {text: metrica}, labels: {align: 'right'},…
-
6
votes1
answer1442
viewsA: Singleton pattern causes error: Using $this when not in Object context
getInstance() is static logo has no reference (or cannot access) to attributes of a object then it is not possible to use the $this. Need to change the $this for self either via properties or method…
-
4
votes1
answer2338
viewsA: Digital Line Boletus Field Mask
With the plugin inputmask can create the mask by passing only the pattern, the 9 means that only numbers are accepted. Html: <input type="text" id="boleto"/> javascript:…
-
1
votes3
answers529
viewsA: Login with validation system
Error 500 is programming problem, in which case you should consult apache log to see the error messages or enable the display of them only in the script with the lines, are put at the beginning.…
-
0
votes1
answer40
viewsA: Permission in PHP
Missing extract database lines with mysqli_fetch(). mysqli_query() returns a Resource or a false, play this in comparison does not give the expected result. function limite($conexao, $id) { $sql =…
-
1
votes1
answer1227
viewsA: Fatal error: Call to Undefined method mysqli_result::fetch_all()
mysql_fetch_all() needs the Mysql Native driver installed, if you don’t have it, exchange it for a fetch() matching while. $sql = "SELECT * FROM " . $table . " WHERE Status = true"; $result =…
-
1
votes1
answer593
viewsA: Insert data from an array into the database by Codeigniter
It is possible to automate part of the process with code generation a mapping of the form field names with the table fields. In the model you can define an attribute called $campos it is an array…
-
4
votes2
answers1177
viewsA: Consult current month birthday in SQL
Use the function now() combined with month() to pick up the current month. SELECT * from top_007 where month(dt_nasc) = month(now())
-
3
votes1
answer3111
viewsA: How to read and interpret a JSON file with PHP?
In place of strpos() can use strstr() to take the last part of the string and compare the loop value with array $tipos with the help of in_array(). $tipos = array('SUPORTE', 'MANUTENÇÃO',…
-
1
votes2
answers270
viewsA: print PHP result on multiple TXT files
After picking up the array with the database information, use the function array_chunk() to divide this array by an arbitrary number (in this example is two). implode() will format each element of…
-
2
votes1
answer44
viewsA: Number of fields - PDO
Seen by the comments the problem was that your Insert sent a null to a field ($testF) not null. The cause is in the html form where the input had the attribute disabled. So the solution is to remove…
-
3
votes1
answer487
viewsA: Validate data with PDO
Who has the result of the consultation $linha and not $busca. If you will return only one record use fetch() in place of fecthAll() this eliminates an unnecessary foreach.…
-
8
votes2
answers3537
viewsA: What is the function of the «??» operator (two questions) in PHP?
The ?? is known as null coalescing was added in the PHP 7. Its functionality is to return the first operand if it exists and is not null otherwise returns the second operand. The code in PHP 7…
-
3
votes2
answers244
viewsA: I’m having trouble trying to list data from a mysql table
The correct thing would be to initialize conn in your DAO controller. This code does not work because it (conn) is null. Only instantiated in the method insert() but not in the select(). Once the…
-
4
votes1
answer2072
viewsA: How to resolve "Call to a Member Function prepare()"?
The constructor of a class in PHP must be named two underlines followed by the word construct. In your code there is only one underline, this does not invoke the defined constructor but the default…
-
1
votes1
answer98
viewsA: Strange values when generating array in a dynamic object in PHP
I don’t know the end of the code, a way to take only the 'dynamic properties' and delete the ones defined in the class as $keys and $values is to take the return of get_object_vars() and execute a…
-
3
votes2
answers362
viewsA: Remove line break after each INSERT
Use the trim() to remove line breaks. $voucher = explode("\n",$voucher); foreach ($voucher as &$varray){ $gravar = mysqli_query("INSERT INTO `vouchers` (voucher, tempo) VALUES…
-
5
votes3
answers322
viewsA: How to know the names of the array positions in php?
To take the name of an array’s keys one way is to use the function array_keys() $arr = array('modulo' => 2, 'categoria' => 6, 'tipoLicenciamento' => 3); $chaves = array_keys($arr); echo…
-
1
votes4
answers318
viewsA: How to get the last segment of the path?
Can use preg_split() to capture all values between bars and call array_reverse() to reverse the order of the elements, playing the latter as the first. preg_match() checks if the current elm starts…
-
2
votes1
answer255
viewsA: SQL command does not work with select
In the code there is a string would with update if they are not sent to the bank they do nothing. Basically what was missing in your code was a mysqi_query(). You can simplify if with a status…
-
2
votes1
answer213
viewsA: array repeating results
Has a for in its code and foreach is specified $estados[$i] when only a foreach would solve. $valor is equivalently $estados[$i] then when it comes time to assemble the options just call him.…
-
3
votes2
answers61
viewsA: Error in PHP code
Syntax error table names or fields should not be in single quotes. This holds for both select and update code. "SELECT * FROM '".$this->tabela."' ^ ^ | causa do erro |…
-
3
votes2
answers404
viewsA: mysqli_fetch_array without using while
If you have the mysqlnd installed can use the function mysqli_fetch_all() she is equivalent to fetchAll() PDO ie returns all the results/rows of the query at once. $result =…
-
2
votes2
answers606
views -
1
votes5
answers4863
viewsA: How to make a regex that ignores non-alphanumeric characters?
Use only \w+ this will match all the characters in the intervalode and A-Za-z0-9 once or more. console.log('m#o#e#d#a'.match(/\w+/g)); console.log('m,.o,e.d...a'.match(/\w+/g));…
-
2
votes2
answers257
views -
0
votes3
answers914
viewsA: Insert two points into the string
Another way to solve this problem is to use the function substr_replace(). What makes it work the way you want it is to report the fourth argument as zero. Thus will be added the character in the…
-
2
votes3
answers3361
viewsA: How to convert 0 to null (Error inserting NULL into an INT field from a variable)
You can use a ternary to properly format SQL if there is a value that gives the variable its own value plus simple quotes (in the case of a varchar for numeric types do not add them) otherwise…