Posts by rray • 66,288 points
1,220 posts
-
1
votes2
answers63
viewsA: Taking only 4 items from 1059 instead of all
Instead of iterating the integer array(json), specify which key you want (items). The code below iterates the keys total_count, incomplete_results that have scaler values (simple) so a Warning is…
-
1
votes1
answer26
viewsA: How to count equal records in a column and get the same number?
With php5.5 can combine function array_column() that extract the input values and return them as a new array, with use of the function array_count_values() that will tell you how many equal values…
-
4
votes1
answer116
viewsA: How to pass an array in a WHERE condition
Exchange the where() by conventional where_in(), the first only compares a value with a certain column ex: WHERE nome = 'fulano'. The second compares a series of values with a column to sql…
-
2
votes1
answer868
viewsA: How to access a variable codeigniter array
If the method $this->perfil->perfil($id) should return only a single record change its return from result() or result_array() for row() so the zero index is not created and it is possible to…
-
1
votes1
answer69
viewsA: error in my_sql to PDO conversion
$rows = $result->fetchAll(); Already returns an array, so just do a foreach with $rows. The problem is yours do-while that overwrites all the time $rows }while ($rows =…
-
3
votes1
answer51
viewsA: I can’t make select
$consulta does not exist in the view because it was not defined, see the controller code: $this->load->view('v_home', $consulta); To set the name of the variable that will be manipulated in…
-
2
votes2
answers1429
viewsA: Problems with mysqli_result as array
It may be more practical to make the function return the array with the data, then add the call from mysqli_fetch_assoc() while and at the end of it returns the variable ($arr) containing the…
-
2
votes1
answer53
viewsA: Eclipse Configuration
To change the number of items displayed on that grid, first left-click the down arrow in the bottom right corner. Menu access Configure Contents, in the settings box that appears look at the bottom,…
-
2
votes1
answer57
viewsA: Upload file with post
Fields of the type file are not caught by $_POST (pure php) or input->post() (codeginiter) but by the capenga lib that comes with the framework or the $_FILES //configuração do formato, tipo e…
-
4
votes4
answers1225
viewsA: How to block website and leave free only for some ips?
You can use the function in_array() to verify which ips have access to the site. $validos = array('10.11.30.175', '10.11.30.182'); if (! in_array($_SERVER['REMOTE_ADDR'], $validos)) die('Site em…
-
4
votes1
answer44
viewsA: Where’s the mistake I can’t see?
The current check compares if the result is isset() is true and if imagem_opcao is galeria_imagem. I also suggest you change the and for && since they are not equal, have different…
-
4
votes3
answers533
viewsA: How to compare Mysql to an array?
Use the function implode() to transform the array into a comma-delimited string, this goes to the key IN $inteiro = array(10,3,12); $sql = 'SELECT * FROM turma WHERE idTurma IN('. implode($inteiros,…
-
0
votes1
answer1200
viewsA: Argument 2 passed to sqlsrv_connect() must be of the type array, string Given
The passage of the arguments is exchanged on sqlsrv_connect() the signature of the function is sqlsrv_connect ( string $servername [, array $connectionInfo ] ) Change: $this->Coninfo =…
-
6
votes2
answers833
viewsA: Varchar or Datetime?
The problem of using a date field of how varchar it’s time to order, CREATE TABLE `datas` ( `id` int(11) NOT NULL AUTO_INCREMENT, `data_varchar` varchar(45) DEFAULT NULL, `data_date` date DEFAULT…
-
3
votes1
answer386
viewsA: Return date with Brasilia Timezone
Use the function date_default_timezone_set() to set the time used by the date functions. Add this code to the first line of your file. date_default_timezone_set ('America/Sao_Paulo'); Another way is…
-
4
votes2
answers184
viewsA: How to turn an INI file into an Array?
Use the function parse_ini_file(). If there are 'fields' with the same name, the latter will enter as a key in the array. To avoid this situation, pass true as second argument, so the array will be…
-
14
votes5
answers2081
viewsA: Hide the last 4 numbers from a string
Another option is to use strrev() to invert the string or 192.168.39.134 flipped 431.93.861.291 and apply a regular expression to replace the first 4 numbers that limit is set in the fourth argument…
-
1
votes1
answer94
viewsA: Better formatting of xhtml files
Yes there are options for this. 1 - First check if the indentation is breaking each attribute per line on: Window>Preferences>Web>HTML files>Editor Uncheck the multiple split option ...…
-
2
votes1
answer55
views -
1
votes2
answers180
viewsA: Javascript connection to the database does not work
In the procedural style of Mysqli almost all functions ask as the first argument the connection, mysqli_real_escape_string() is not the exception. Change and the other lines of: $nome =…
-
3
votes2
answers124
viewsA: Form: one choice is free, two have to charge. How do I?
With Jquery you can use $(":checkbox:checked").length this will take all checkboxes marked and return an array, the property length returns the number of elements in this array. With this just apply…
-
0
votes2
answers32
viewsA: How do I perform a php Insert where data is passed on by a json that has an object
To catch the json in this case do not use include right is file_get_contents() Change: $json = json_decode(include("novavaga.json")); To: $json = json_decode(file_get_contents("novavaga.json"));…
-
1
votes1
answer27
viewsA: How do I make echo "Success" and "Failed to appear below the form?"
Only with PHP, one way to do this is to create a div below the form and a variable with the operation message, it must be set before the if that checks if the $_POST exist, so she ($msg) comes into…
-
3
votes1
answer713
viewsA: How to pass information from a JSP page to a Servlet
To get the value of a form field or parameter value of a query string, use the text getParameter() of the object request. url: www.teste.com? parameter=test How to get the value in Servlet: String…
-
2
votes2
answers1760
viewsA: How to assign values to an associative array in php?
Assign by passing the key, this is for both associative and numerical arrays. So just match the key ($key) with the array and assign the new value. foreach($arr as $key => $value){ $arr[$key] =…
-
4
votes3
answers108
viewsA: Instantiation of objects in php
It is not possible to assign objects created directly to a property or function calls. In php this should be done in the constructor. Only fixed values and some types of expressions are allowed. In…
-
7
votes3
answers885
viewsA: How can I check if the last position of the array has been filled?
You can use the function end() to take the last element of the array and check whether it has value or not. $arr = [1,2,3, null]; $ultimo = end($arr); if($ultimo){ echo 'tem valor: '. $ultimo;…
-
6
votes9
answers30430
viewsA: How to debug code in PHP?
The most practical option to debug in PHP is to install a debbuger as Xdebug or Zend Debugger in conjunction with an IDE (Eclipse, Netbeans, Phpstorm etc) this combination allows: That PHP code be…
-
1
votes1
answer69
viewsA: How do I get PDO to list Array with Correct Types?
Check whether PDO::ATTR_STRINGIFY_FETCHES is marked as false this option can be applied via setAttribute() or directly in the PDO constructor. $opt = array(PDO::ATTR_STRINGIFY_FETCHES => false);…
-
0
votes1
answer321
viewsA: Update carrinho codeigniter
Problem: Like the update() is out of foreach only the last item will be updated see that the assignment to $update is remade every lap of the second foreach. Solution It seems that $value and…
codeigniteranswered rray 66,288 -
1
votes1
answer26
viewsA: Release parameter on striptag
You can create an anonymous function that returns the strip_tags() in the array_map(). $tags = '<a><p><iframe>'; $arr = ['<a>asdasd</a>', '<p>dois</p>',…
-
11
votes7
answers21016
viewsA: What does the term Fallback mean?
Fallback means "plan B" or emergency plan, that is if the configuration set by the programmer fails there will still be a default option that will take a valid value. It has no correspondence with…
terminologyanswered rray 66,288 -
3
votes1
answer117
viewsA: How to use a variable in the array_walk?
To documentation says that when using array_walk() only the values will be changed by default or the structure will not be changed. When callback does not respect this rule the behavior of the…
-
0
votes1
answer46
views -
1
votes4
answers541
viewsA: Concatenate 2 PHP variables into SQL statement
You can mount the concatenation with the function sprintf() also, the %s are exchanged for the relevant variables (values) in the order they appear. $passo = $_POST['passo']; $update .=…
-
5
votes2
answers382
viewsA: Format value with explode and implode PHP
It is simpler to leave this task with a specialized function/class. This date formatted is known as W3C, to pick up part of the date use the Datetime class and method format() $d =…
-
4
votes1
answer844
viewsA: Why does my PHP script only return me Resource id #4?
mysql_query() returns a Resource or a false in case of an error. To extract the information from it you need to use the mysql_fetch_assoc() or other flavor of return. Three important things, mysql_*…
-
2
votes2
answers101
viewsA: How to select a field with MAX()+1 and use in an INSERT?
fetchAll() Returns an array in the following structure: [0] => array(OrderNew => 10) to access it is necessary to specify the Intel zero $row[0]['OrderNew']; As the return is always a change…
-
13
votes4
answers10585
viewsA: What is database normalization?
Data normalization is a set of rules applied to relational database tables in order to maintain data consistency, avoid duplication/redundancy, and problems with removals or updates of records. The…
-
5
votes1
answer1034
views -
2
votes3
answers717
viewsA: How to list files in a directory?
Check whether $fileInfo is a file or directory, two methods can do this depending on the case one isDir() and or isFile(). foreach ($dir as $fileInfo) { if(!$fileInfo->isDir()){ $ext =…
-
2
votes2
answers7910
viewsA: Read text file and play the content in positions in an array!
If the file is not too large, you can use the function file() it will convert your file into an array. $f = file("mapa.txt"); foreach($f as $item){ echo $item .'<br>'; }…
-
22
votes4
answers8677
viewsA: What’s the difference between data and information?
Datum is something crude, like the 29 or the M of your question. They alone make no sense, it is not possible to draw any conclusion of what they are, what they serve for or what context they belong…
terminologyanswered rray 66,288 -
7
votes3
answers68
viewsA: regex Return false?
You need to escape the \d or pass the argument i in the regex builder. var pattMax = new RegExp('^(max)(\d{1,3})', 'i'); pattMax.test(rule); //false? if(pattMax.test(rule)){ console.log('é max…
-
3
votes1
answer81
viewsA: PHP function only works on the first call
In preenche_time_combo() every call from mysqli_fetch_assoc($result) is altering/emptying the variable $registro out of function (change by reference), so the second call does not work. The simplest…
-
3
votes2
answers615
viewsA: How to find out if an array is multidimensional or not in PHP?
One way to know that is to use array_map() to apply the function is_array() in each element of the main array and sum the elements of the return array, if zero is a simple array if it is greater…
-
3
votes3
answers249
viewsA: Extract only numbers from a Javascript text box
You can use regular expression to replace all characters that are not numbers, this is represented by \D, the g in the end means that the substitution is done on all found elements by default…
-
4
votes3
answers112
viewsA: swap Z for S char between vowels in a string
You can use two groups to check the existence of vowels between the Z, after captured just play them $1(first group), $2(second group) between the S $str = 'TEREZA , CEZAR, BRAZIL, ANZOL'; echo…
-
3
votes2
answers536
viewsA: How to remove a part of the string at the beginning or after the space?
If it’s just to replace the HE at the beginning of names/words use the \b, so no middle characters are replaced in the string. Example - ideone <?php //exemplo 1 $str = 'HELIANE HELIAS'; $str =…
-
2
votes1
answer41
viewsA: It is not writing in the database, and the columns have numbers as names
It is NOT advisable to use numbers as identifiers of tables or columns but it is possible to use them as long as the names are escaped with backticks (crase), this is also for special characters,…