Posts by rray • 66,288 points
1,220 posts
-
0
votes3
answers1031
viewsA: As returns only the file name without the path
Can match strrchr() which returns the last part of a string after the delimiter (it enters together as return) and trim() to remove the / remainder. $arr = array('public/html/p1/js/f.js',…
-
2
votes2
answers63
viewsA: How to make 2 queries in different database with PHP
The mysql_* functions should no longer be used should one opt for Mysqli if it is not possible simply inform the fourth argument of mysql_connect() true, this will create a new connection. It should…
-
3
votes2
answers141
viewsA: Handling and Error Handling
The first point is do you really need these assignments? can’t use the $_POST direct? If you can’t the two best ways to test the existence of a key are. 1) isset()/empty() plus the use of the…
-
6
votes3
answers1606
viewsA: Count how many times a string appears in an Object
If you don’t have a special reason to work with simplique objects by returning an array in the json_decode(). With this you can extract the values from the key type (array_column() php5.5) and apply…
-
2
votes1
answer971
views -
1
votes1
answer259
viewsA: Nusoap return $HTTP_RAW_POST_DATA empty
The use of $HTTP_RAW_POST_DATA is obsolete since php5.6 and removed in php7. Instead use: $info = file_get_contents('php://input');…
-
2
votes1
answer304
viewsA: PDO inserting null
There are some strange things in these codes, the main problem is not popular the object $user, the calls of set() must have some value that comes from the form in the example I used fixed values.…
-
5
votes2
answers83
viewsA: With making a Count within the array
If you’re using php version 5.5 combine the function array_column() to extract a key from a multidimensional array. With this call array_sum() adding together the elements: $arr = array(array('id'…
-
6
votes2
answers4183
viewsA: How to discover a collation of a table or database using an SQL query?
You can list the collation of each table of a given table using the information_schema, as follows: SELECT table_name, table_collation FROM information_schema.tables WHERE table_schema =…
-
4
votes1
answer1012
viewsA: Create variables with a dynamically shaped array
To transform elements of an array into variables use the function extract(), if there are many elements it does not make much sense to use. It is recommended to pass the option as argument EXTR_SKIP…
-
5
votes3
answers753
viewsA: CPF Regex with Laravel
The biggest solution would be to normalize all values in the column without formatting. The provisional way is to treat the comparison values in the same way or by removing the formatting. You can…
-
16
votes3
answers289
viewsA: Condition Yoda, good reason to use?
The only advantage of Yoda conditions is change the error type, logic (assignment instead of comparison) by a syntax. It is not possible to assign something directly to a number or any other type.…
encoding-styleanswered rray 66,288 -
12
votes2
answers34544
viewsA: How to get column names from a table in SQL Server?
Another way to get the column names of some table is query sys.Columns using the function object_id() that takes the table/view name and returns its internal id. This works from SQL Server 2008…
-
3
votes7
answers185
viewsA: Capture year outside the regex
If an invalid year starts from 3000 you can use the following regex [3-9]\d{3,}. She marries a number that starts between 3 or 9 following from which she wants other digits at least three times.…
-
2
votes1
answer615
viewsA: Warning error: mysqli_fetch_array() and no error returned in mysqli_error
There are two instructions mysqli_fetch_*() the second receives an array when it should not exist or should receive a Resource. if(mysqli_affected_rows($con) == 1){ $resultado =…
-
3
votes3
answers175
viewsA: Exclusion via regex
To capture the microsecond you can use the following regex \.\d+(")$ it says to capture at the end of the string a point followed by one or more digits followed by a double quote which is a group.…
-
5
votes2
answers517
viewsA: How to join two array
You have objects you can cast from Stdclass to a simple array using $arr = (array) $lista; I believe the simplest way is to foreach and check if the key of the first array ($arr) exists in the…
-
4
votes1
answer507
viewsA: String binding of SQL tables instead of id
For the use of Foreign key, it is necessary that the database ENGINE is INNODB ? By using this engine the database automatically guarantees referential integrity it can be guaranteed via application…
-
6
votes4
answers2820
viewsA: What is the difference between "notice" and "Warning" in PHP?
One of the things that change is the value of the constant, 2 for Warning and 8 for notice. Basically they’re different information levels. Indicate that the code executes some instruction that can…
-
4
votes2
answers559
viewsA: Regular Expression for password
You can use the following regex /\d.\d|\d{2}./ she says she should marry a number followed by anything and then another number or (|) two numbers followed by anything. Examples:…
-
1
votes1
answer79
views -
1
votes3
answers100
viewsA: Search first name in mysql field before MYSQL space
Can convert a datetime column to date only using cast(). Or by formatting the date with date_format() SELECT * FROM tabela WHERE CAST(campo as date) = '2016-02-21' or SELECT * FROM tabela WHERE…
-
7
votes1
answer2505
viewsA: How to comment / document a table?
Yes it is possible just add the clasp COMMENT in the definition of the column or table. CREATE TABLE pessoa( id INT NOT NULL AUTO_INCREMENT COMMENT 'chave primária', nome VARCHAR(50) COMMENT 'coluna…
-
3
votes1
answer1657
viewsA: Problem with id AUTO_INCREMENT in SQL
Omitting the names of the columns of the Insert means that the values will be passed in the same order. INSERT INTO teste VALUES ('Meu nome', '[email protected]'); This Internet is understood…
-
2
votes3
answers5128
viewsA: How to allow only numbers and dashes with preg_replace?
You can use a list by denying digits (\d) and the hyphen (-) anything married is replaced by nothing. $str = "abaaksjjkdhaf 29023487 - 1kfksdjf"; echo preg_replace('/[^\d-]/i', '', $str); Exit:…
-
4
votes1
answer105
viewsA: Remove string numeric sequence
To capture/replace three or more digits in a row use regex \d{3,}. \d means numbers (0-9), keys act as a quantifier in case they require three digits or more to be captured. $str = 'CONECTOR BNC…
-
5
votes2
answers1943
views -
3
votes1
answer810
viewsA: Insert Mysql data with file . txt
The function mysqli_query() excuta only one SQL statement at a time, the semicolon makes the delimitation between the instructions so this generates a syntax error. There are two ways to solve this…
-
18
votes3
answers514
viewsA: What is the purpose of the software development sequence steps?
Each of these steps tries to isolate part of the problem, sometimes this division is not very clear. Requirement: At this stage the development team has the first contact with the problem and the…
-
20
votes5
answers991
viewsA: What is UX (User Experience)?
UX is an area of knowledge that studies the interaction of users with the product or object whether it is a software or physical device in order to facilitate its use. In other words, UX 'thinks'…
-
4
votes2
answers354
viewsA: How to generate an array of years dynamically containing the index as the year and the value as the year itself?
Can use range() to generate the list of years and array_combine() to transform the value of $keys in the keys themselves: $keys = range(2015, 2020); $arr = array_combine($keys , $keys); Or else:…
-
2
votes2
answers377
viewsA: How to find the second largest number
Can create two most internal query takes the two largest records and sorts from largest to smallest (DESC), with this the most external query picks up the result and intervenes it or is ordered from…
-
20
votes3
answers9451
views -
2
votes2
answers473
viewsA: column with invalid accent
When the name of the identifiers (tables columns ect) have accented characters or other types use the escapes, in the case of SQL SERVER are square brackets ([]) Change: SELECT descrição FROM ...…
-
8
votes2
answers1746
viewsA: How do you count the number of times a word repeats itself in a sentence?
You can use a regex to search for the exact word using the search term enter the anchor \b to function preg_match_all() returns the number of occurrences captured, in case two once quer or qualquer…
-
5
votes5
answers590
viewsA: Remove chunk from a string
Can use function strstr() passing the third argument that returns only the left part of the delimiter: echo strstr('32137hyb8bhbhu837218nhbuhuh&3298j19j2n39', '&', true); Returns:…
-
3
votes1
answer80
viewsA: php regular expression
Can display the source code of a page with highlight_string(), this prevents it from being rendered by the browser, so just something like: highlight_string($resultado);…
-
19
votes3
answers262
viewsA: How to validate strings?
You can use a fixed part of the string (site address) and dynamic the part of the movie id: ^www\.adorocinema\.com/filmes/filme-\d+$ Says search at the beginning of the line (^) for www followed by…
-
2
votes1
answer251
viewsA: Functions that are nicknames (aliases) should be used or not?
The ideal is always to use the root 'language' or the function’s orginal name. The team that takes care of the development does almost everything to maintain the compatibility newer versions with…
-
4
votes1
answer107
viewsA: Rollback method does not work in mysqli extended class
This Function doesn’t work with non Transactional table types (like Myisam or ISAM). According to the PHP manual alert. Only tables with Innodb or NDB engine support logo transactions…
-
1
votes2
answers1174
viewsA: Export sql server query result to txt file on apache server automatically
Use file_put_contents() to create the file by passing a string ($conteudo) which will have all the fields of consultation set by - who does this implode() $conteudo .= ''; while ($row =…
-
5
votes1
answer6033
viewsA: Codeigniter 2 with variable reference error in PHP version 5.6
The Codeigniter framework has a great legacy, so it uses some techniques that have fallen out of use. The problem here is the & in the signature of the method get_config(), which requires the…
-
9
votes4
answers1609
viewsA: Mysqli_fetch_row() expects Parameter 1 to be mysqli_result
In a UPDATE, no value is returned, such as would be in a SELECT. It is therefore not necessary to use the function mysqli_fetch_row() to find out whether or not the operation was successful with a…
-
1
votes2
answers98
viewsA: MS SQL server Storeprocedure returning resultset
Initially put a parameter in arrayx() to treat SP return. Use the function sqlsrv_next_result() to know if there is something returned by the bank, if yes do the fetch_array() of all items and…
-
3
votes2
answers2208
viewsA: SQL to compare hours and minutes when Timestamp in Postgresql
You can apply a date cast to time to compare only hours/minutes, just use :: followed by the type. SELECT * FROM "Tabela" WHERE "Coluna_1"::time > "Coluna_2"::time Example - sql fiddle…
-
2
votes2
answers142
viewsA: How do you detect three equal numbers?
Another way to solve is to join each group of three and check that all are equal, note the initial value of $i went from zero to one, to identify the multiples of three: $sorteados = array(); for($i…
-
1
votes1
answer221
viewsA: Insert and PDO problem
The problem seems to be that your method con_clients_add is being interpreted as class controller, so on the first call. A method with the same class name in some circumstances is considered as…
-
8
votes4
answers2310
viewsA: I cannot disable a checkbox with enable = false
To deactivate (leave it gray and unusable) a checkbox the correct property is disabled and not enable Change: document.getElementById('ind_permite_inc_autori_chkb').enable = true;…
javascriptanswered rray 66,288 -
21
votes3
answers6900
viewsA: What’s the difference between Return and break in a switch case?
The return ends the execution of the method regardless of where it is and returns the value. The break force (manually) the output of a loop or conditional in case the switch. In the second code if…
-
3
votes1
answer77
viewsA: It is unusual to have a class called mysqli the getInstance() method return the Fatal error: Uncaught Error: Call to Undefined
Do not mix Mysqli with PDO, use one or the other but not both. As comments and documentation there is no method getInstance() in class mysqli. The code is more for PDO than Mysqli so to fix the…