Posts by rray • 66,288 points
1,220 posts
-
12
votes4
answers702
viewsA: Column 'idusuario' in Where clause is ambiguous
This error means that the database does not know which column you are using/referencing because this name exists in two or more tables. To solve this is simple just give an alias for one of the…
-
9
votes3
answers342
viewsA: How to escape characters in Windows Batch?
To clear characters use the circumflex accent ^
-
3
votes2
answers111
viewsA: Convert function for next ASP to PHP
How the goal is to compare the value of letra with the current array item str(i). One way to do this with php is to create a template through an array where the keys are the letters (A-Z) and the…
-
1
votes3
answers69
viewsA: How can I check equal variables within a while
Create a variable ($anterior) that stores the previous record, and then make the comparison. Remember to update it to the current value at the end of while. $anterior = array('id' => 0);…
-
5
votes4
answers9035
viewsA: Mask Car plate in jQuery
You can use the plugin Robinherbots inputmask besides jquery add the jquery.inputmask.Bundle.js file. The code for mask is composed of three letters (A) a trait (-) and four digits (9) javascript:…
-
0
votes1
answer238
viewsA: Return all data to a mysql_fetch_assoc
+= does not work to add an item to an array, assign it with square brackets. Change: while($l = mysql_fetch_assoc($sql_select)){ $result += $l; } To: while($l = mysql_fetch_assoc($sql_select)){…
-
1
votes1
answer245
viewsA: Insert_batch or update_batch - Codeigniter
This (only the last item is processed) happens because the key that closes the foreach is in the wrong place it should be at the end. As you need to check what to do with each record it doesn’t make…
-
4
votes2
answers64
viewsA: Use 'today' as default value in PHP method
Just as it is not possible to initialize properties of a class expressions or function calls that depend on something with the code already running. An option would be to already set this date,…
-
2
votes1
answer25
viewsA: Error in obtaining bank value
$result is an array returned by a fetchAll() this way it always comes with Index Zero. The correct way to access is: $result[0]['ID_PUBLICATION'];…
-
1
votes3
answers290
viewsA: Doubt with Insert in Postgres Bank
The name seems to be of type array, in which case it is necessary to inform the correct syntax keys are required. INSERT INTO empresa (id, nome) VALUES(2, '{teste}')
-
1
votes2
answers479
viewsA: Doubt about method of sum
public static void main(String[] args) { int[] vetor = new int[10]; int numeros; Scanner e = new Scanner(System.in); for (int i = 0; i <= 10; i++) { System.out.println("digite os valores dos…
-
4
votes5
answers676
viewsA: Individual methods or parameters in Mysql queries?
In this case, creating three methods fragments your logic unnecessarily so leaving logic in one place just seems the best alternative. You can swap this if for array as you are basically choosing a…
-
0
votes3
answers270
viewsA: variable interval php time
You can simplify creating date or time periods with the class DatePeriod in the construction are necessary three arguments the beginning of the period, the interval and the end. If possible migrate…
-
1
votes1
answer178
viewsA: Highcharts - Line Chart with date
The problem seems to be the way the totalization in json is like the timestamp when it should be for the month. I wrote a function that does this. Basically what it does is create an array of 12…
-
5
votes1
answer167
viewsA: Locate line that starts with negation of the expression
Combine the anchor (^) starting with the negative lookhead (?!) this will identify lines that do not start with CAKE ^(?!BOLO) Text: BOLO BOLO CHOCOLATE RECEITAS BOLO This example houses the last…
-
10
votes4
answers10900
viewsA: Is it possible to use the ternary operator under several conditions at the same time?
Yes it is possible but DO NOT CHAIN TERNARIES in PHP because it makes the evaluations of the expression from the left different from most languages which in practice returns strange results (the…
-
6
votes3
answers559
viewsA: Document protocol
Approach with Myisam Prerequisites: Have a composite primary key. Table engine must be Myisam. Disadvantages: If the table has any foreign key the referential integrity should be implemented via…
-
9
votes2
answers2954
viewsA: What is a scalar variable?
A scalar variable is a simple value like a int, float, string, Boolean. This type can be accessed/manipulated without any additional instruction, just call it, other than a array or some other you…
-
2
votes1
answer367
viewsA: How to send more than one checkbox option by email?
Use the implode() to transform the sent checkbox array into a string by a delimiter, made concate this result to its message: $selecionados = !empty($_POST['checkbox']) ? implode(', ',…
-
2
votes2
answers1036
viewsA: Make an SQL query with codeigniter
The first step is to configure the file application/config/database.php with database information such as driver, user, password, database name and other options $db['default'] = array( 'dsn' =>…
-
0
votes1
answer185
viewsA: Error to the popular SELECT - Warning: mysql_fetch_array() expects Parameter 1 to be Resource
getAllServicos() returns an array with the database results, it makes no sense to pass it to the legacy function mysql_fetch_array(). You can go right through a foreach: <?php…
-
2
votes2
answers193
viewsA: How to delete both duplicate values from the array?
You can remove duplicate items and their singular by diffraction the arrays twice $a with $b and of $b with $a. The first call from array_diff() returns the goods: 3, 30 and 40 and the second: 70…
-
6
votes2
answers103
viewsA: What does the expression "/ (?:(?:cats?|dog):)? /" do?
Your regex seems to search for a 'field' in the string in the pattern: gato: gatos: cachorro: (?:) means that your regex should match this standard but the catch does not go to the group or is a…
-
1
votes2
answers78
viewsA: Grouping Array Results out of Loop
When wearing something like $var = $novo within a loop what happens is at each loop/iteration the value of $var will be overwritten and after the loop will have the last value. If you want to take…
-
2
votes2
answers433
views -
2
votes0
answers54
viewsQ: Difference between statement and expression?
What is the difference between a statement and an expression in the context of programming languages? Could show an example of how I identify both in a code snippet? What would be the best term or…
terminologyasked rray 66,288 -
10
votes4
answers3000
viewsA: Equivalent to the conditional or ternary operator in Kotlin
Kotlin has no ternary operator but a if can return a value (i.e., it is treated as an expression) and function in the same way, with the detail is you are bound to have a block else. As stated in…
-
4
votes1
answer36
viewsA: Get BD name on a mysql connection
Use the function database() Mysql it returns the name of the connection database. SELECT database() In php with Mysqli it looks like this: $db = new mysqli('localhost', 'usuario', 'senha',…
-
5
votes2
answers98
viewsA: What’s wrong with this search form?
The main error occurs because mysqli_query() expects exactly two arguments the first is always connection and the second the query. Change: $busca_query = mysqli_query("SELECT * FROM empresa WHERE…
-
0
votes1
answer36
viewsA: Query about opening array form in PHP
Yes there is (when using, both generate the same result an array.), the compact syntax ([]) is only available from 5.4 for earlier versions only array() works. To maintain greater code compatibility…
-
5
votes3
answers115
viewsA: The logic behind how PHP interprets string and number concatenation?
First PHP concatenates the value hello plus the number 1 this generates an invalid number so it is converted zero so make the account 0 + 2 and contact the result of the sum with 34 ending as the…
-
2
votes3
answers164
viewsA: How to add a JSTL attribute under one condition?
Use a ternary to check the condition make him write or not the selected, the way it is always added selected="false" causing all elements to have this attribute. <option…
-
1
votes2
answers660
viewsA: A regular expression to detect acronyms of Brazilian highways
You can assemble two regex one more generic to validate only the format of the highway and another more specialized that guarantees with greater chances your existence. According to the research…
-
6
votes1
answer3221
viewsA: Error Call to Undefined Function split()
The function split() was removed from php7. The closest is explode() or preg_split(). Change lines: $ab = split("\n", $lista); list($card, $mes, $ano, $cvv) = split("\\".$delimitador, $ab[$x]); To:…
-
12
votes3
answers1519
viewsA: What is 'final' in PHP?
The keyword final can only be used in classes and methods basically means that a class cannot have any daughter (inheritance). In methods it means that subclasses cannot override/modify this method.…
-
1
votes1
answer286
viewsA: Bookmarks Eclipse Editor
Shortcut via toolbar These are spaces and other characters like tab and line break. There is a shortcut in the toolbar that enables/disables this setting. The button is that performs the action is…
-
4
votes2
answers422
viewsA: Capture words using Regular Expressions
All regular expression based on PCRE is necessary to put the most common delimiters are the bars \ but may be other non-alphanumeric characters. You can simplify your regex and capture in a group…
-
8
votes2
answers1302
viewsA: Mask credit card numbering
The simplest option is to use the function substr_replace(), in that reply has more details. Another alternative is to use the function str_split() to break the string into an array with four…
-
1
votes1
answer91
viewsA: Compare Explode Array with select option text
Compare the value that comes from the database with the skill array with the function in_array() if assigned $selected the selected value. Then mount the template with printf(). while($row2 =…
-
3
votes1
answer518
viewsA: SELECT ... WHERE name LIKE bind_param
The LIKE in numbers (integers, double etc.) i for s. Also missed calling the method execute() after the bind_param() because it sends the query to the database without it is not possible to recover…
-
2
votes2
answers791
viewsA: Function to summarize string in php
You can simplify your role with substr() or mb_substr() how to return and change the function signature to add the ... if no argument is passed: function resumo($string, $chars=0) {…
-
2
votes1
answer50
viewsA: Error while trying to list objects that are in the database when using Foreach();
Your function returns the wrong value should return $uniformes and not $uniforme Change: return $uniforme; To: return $uniforme; Remember to create a variable or pass an array to foreach, you can do…
-
3
votes3
answers58
viewsA: Why does the use of parentheses affect a mathematical expression combined with a concatenation?
Parentheses as in mathematics give priority to some operation, so the first echo works as expected or is does the account and then writes the result. P1, P2 = Order of priorities echo "Você nasceu…
-
3
votes1
answer176
viewsA: Separate and merge arrays
I set up a combination that creates a new array with all the products/items grouped by the store code. array_column() extract all store ids, array_flip() invert the values with the array keys…
-
6
votes2
answers76
viewsA: How to instantiate $Pdo = connect() without repeating?
A suggestion is to create a property and connection in your class and pass the connection to it via constructor. So whenever the object (from User) need a connection it will already be open. class…
-
4
votes1
answer84
viewsA: Rename values using if Else
Create a function as you did for the other fields if you want you can use a ternary to make the comparison or if. The difference is that it checks if the value is 1 is active any other is inactive.…
-
3
votes2
answers5747
viewsA: Display whether a person is of legal age or not
Missing add the age check/comparison to the desired value 18 years, this is done with the instruction se. se (idade >= 18) entao escreva ("maior de idade") senao escreva ("menor de idade") fimse…
-
2
votes1
answer41
viewsA: Error updating AUTO INCREMENT
Your parameter is being sent as a string because it generates the syntax error according to the message: syntax to use near ''13''. To resolve this situation indicate the third argument as integer…
-
3
votes1
answer105
viewsA: How to do require_once from multiple locations in one line?
It’s not possible to have a require/include in the class body this generates syntax error. It is also not possible to add an access modifier (public, protected and private) outside a class. The only…
-
2
votes7
answers5040
viewsA: Regular expression for accepting numbers and letters, regardless of sequence
I believe that it is simpler to use two regex one for numbers and the other only for letters and then check the minimum values of each category, since the capture (with the parameter g) returns an…