Posts by Papa Charlie • 8,721 points
217 posts
-
0
votes2
answers73
viewsA: Array with inputs and a specific data!
Use the foreach to change the highlight status when the idFoto match the value of $destaque. I made an example with array on Ideone, but I left here only the loop. The result is the destaque = 1,…
-
2
votes4
answers1630
viewsA: Validate, if already exists does not INSERT
I would use ON DUPLICATE KEY. You can read more on DOC. The advantage is to have a single query for Insert and update. INSERT INTO favoritos( id_user, id_oferta ) VALUES( $login_session, $id ) ON…
phpanswered Papa Charlie 8,721 -
2
votes6
answers392
viewsA: How to make a explode without returning empty values?
It would be a good question if the question were without the use of regular expressions. I see no real reason to use ER in something that is so simple. There are several recommendations on the…
phpanswered Papa Charlie 8,721 -
6
votes5
answers444
viewsA: PHP array types and values
You can change the typing by using (array). $pessoas = new stdClass; $pessoas->nome = 'Papa Charlie'; $pessoas = (array) $pessoas; //output: Array( [nome] => Papa Charlie ) print_r( $pessoas…
-
3
votes4
answers549
viewsA: How to get user name in URL?
Just use parse_url for interprets a URL and returns its components, and subsequently the function trim to remove the / $parse = parse_url( 'http://www.meusite.com/NICKUSUARIO' ); echo trim(…
phpanswered Papa Charlie 8,721 -
3
votes1
answer101
viewsQ: PDO with BIT type
I was now doing an instruction with on Duplicate and I have some fields like BIT. My class DB does the typing using PDO::PARAM_STR, PDO::PARAM_BOOL, PDO::PARAM_INT... but the use of these constants…
-
3
votes1
answer2214
viewsQ: Operation of group_concat
I have some questions related to the use of group_concat, more specifically for performance. When using group_concat can’t use limit. // a query retorna todos os ID's select group_concat( id ) from…
-
2
votes4
answers1123
viewsA: Next record. PHP + Mysql
Note that a loop from 1 to 10 using SELECT * FROM card WHERE id = {$id++} does not guarantee to return 10 records! If between the limit of 10 there is 1 deleted record, then you will have lower…
-
1
votes1
answer84
viewsA: Bundle/Cache CSS files in PHP
Usually when I work with cache, I consider the file change date determinant, so an alternative would be to create a hash using filemtime based on the timestamp of when the contents of the file were…
-
2
votes1
answer83
viewsA: usleep is not working on Windows
According to the DOC, usleep - Delays execution by millionth of a second, soon, usleep(2500) can be imperceptible in the simulation test you are doing. Perhaps the accuracy is not 100% working with…
phpanswered Papa Charlie 8,721 -
5
votes3
answers747
viewsQ: Working with ID limit on large volumes
I have in mind some questions about large volumes of data on MYSQL, concerning the limit of ID. I will give as an example ID guy tinyint to simplify the explanation. In the example the field tinyint…
-
14
votes3
answers4009
viewsA: Why is it important to remove X-Powered-by from response headers? How to remove?
It does not prevent or avoid, in fact, I believe that pass information beyond the necessary informing the environment. I don’t use this header as a safety factor. You can remove it or on INI or in…
-
4
votes1
answer198
viewsA: Array no . ini How to do?
Use the function parse_ini_file to load the INI file and returns the settings contained in it in an associative array. ini.ini a = A b = B c = C args[] = A args[] = B args[] = C php print_r(…
-
0
votes0
answers50
viewsQ: Reference a group of ID’s resulting from group_concat
I have a select that returns me the equally repeated lines, along with the total. I need to reference this ID group to pass as argument. The result of my query is the array below. Basically it…
-
5
votes1
answer94
viewsA: Search in every site
You can use UNION to combine the results of your query. UNION is used to combine the result of multiple SELECT’s into a single result set. ( select nome, concat( "U" ) as `tipo` from user where nome…
-
3
votes1
answer1285
viewsA: Capitalize the first letter of every word in a string with PHP
You can use ucwords to this end: Capitalizes the first character of each word The problem of using ucwords would be when the initial characters are accented, in case they would not be capitalized. I…
phpanswered Papa Charlie 8,721 -
3
votes2
answers56
viewsQ: Remove messages from one caller without affecting the other
I am implementing a messaging system and need to make a way to remove messages from one caller without affecting the other. So-and-so and Sicrano exchange messages: At a certain point, Fulano…
-
3
votes2
answers367
viewsA: Regex in dynamic string X characters, in dynamic content
$str = 'new "x";test>\'ok\'=blabla-bla;||inicio||var77|var2|44AsFGq72A7_7Aq770vAr45|variavel|randomvariavel75|87df".fim("0"...'; preg_match_all( '/\|[a-zA-Z0-9_]{23}\|/' , $str , $out ); print_r(…
-
1
votes2
answers2945
viewsA: Generate a word between defined words [PHP]
Can use shuffle to shuffle the array and use current to return the first element. $array = array( 'Linguagem', 'Língua', 'Lang' ); shuffle( $array ); echo current( $array ); Example…
-
1
votes1
answer389
viewsQ: Multi-action and content notification system
I am trying to understand how best to make a notification scheme for multiple actions and nodes. Basically one should notify someone whenever an action of the type message or enjoy is performed.…
-
3
votes2
answers7951
viewsA: How to dynamically modify CSS using PHP
As said in the comment, when loading a stylesheet even with HTACCESS, the parameters do not transit, at most pass via GET an ULR like: <link ... href="localhost/php.css?parametro=XXX"> In…
-
4
votes5
answers26037
viewsA: Accentuation in the JSON
That is not a 'problem' to worry about, because the decode is responsible for converting the accent. $array = array( 'nome' => 'Paição' , 'cidade' => 'São Paulo' ); $array = array_map(…
-
2
votes3
answers4057
viewsA: Get content that is in parentheses using regex
If (+05) is always fixed, you can use the last 5 characters. $str = 'Mais de - valor: R$3.21 - Tipo: (+05)'; echo strstr( $str , ' - ' , true ) . ' ' . substr( $str , -5 ); Output : More than (+05)…
-
2
votes5
answers667
viewsA: Use JS to relieve PHP
In my view, the question is about using javascript to do PHP work. A request made with ajax can return data formatted in back-end or may receive a json and format for composing a view. My answer is…
-
3
votes2
answers155
viewsA: How to turn strotime output into a variable
I’m sorry if I misunderstood, but what you want is this? $date = array(); for($i = strtotime('Monday', strtotime($beginday)); $i <= $lastday; $i = strtotime('+1 week', $i)) { $date[] = date('l…
-
5
votes1
answer91
viewsQ: Urls in doctype and html tags
1) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2) <html xmlns="http://www.w3.org/1999/xhtml"> HTML5 removed…
-
2
votes1
answer1150
viewsA: Problems with SELECT option with PDO
$conn = new PDO( 'mysql:host=localhost;dbname=DATABASE' , 'USUARIO' , 'SENHA' ); $stmt = $conn-> prepare( 'SELECT * FROM fontes' ); $stmt-> execute(); $result = $stmt-> fetchAll(…
-
4
votes3
answers2046
viewsA: Post a comment and then display without refresh
Let me give you an example - explanation - superficial to pass the idea. Basically you have a DIV-PAI to include comments. When to submit the form via AJAX, just create the formatted element at the…
-
3
votes5
answers4587
viewsA: How to remove ddd from a number
Introducing another approach, you can work the string as an array (faster than substr) and recover the first 2 characters, so you have the DDD and phone in separate variables. $phone = '5198765432';…
phpanswered Papa Charlie 8,721 -
9
votes5
answers2967
viewsA: Take all the names and put comma to separate them
Another way would be to simply remove the last element of the array, use implode to place the commas if there is enough name for the separation and then replace the last element back. function…
phpanswered Papa Charlie 8,721 -
2
votes1
answer479
viewsA: Table structure for PHP friendship systems
This is the simplest way having user and friend. In the query you check whether User ID matches the ID of friend and vice versa, in usuario or in usuarioamigo select * from amigos where ( usuario =…
-
5
votes5
answers1659
viewsA: Default parameters
There is no way to 'skip' the first parameter, but what you can do is a condition for the null be worked with the parameter. function exemplo( $par1 = 1 , $par2 = 2 ) { return ( ! isset( $par1 ) ? 1…
-
8
votes3
answers2493
viewsA: How to choose the highest value of an array?
There is a function to sort an array by keys in descending order - krsort Use krsort to sort the array downwards and just use Current to retrieve the first element, because krsort maintains the…
-
6
votes1
answer402
viewsQ: select like over 3 million lines
I have a Maxmind table, with more than 3 million cities. I created the indexes for a simple select and is at satisfactory performance. The problem is that I am using an autocomplete and for that my…
-
5
votes3
answers626
viewsQ: How does php guarantee a single session_id?
Which algorithm used to secure a single session_id()? I wanted to know what the creation and verification is like to ensure that such an ID does not collide with an existing one? I need to create…
-
1
votes2
answers79
viewsA: PHP - online lambda functions
My proposal would be to rename the class to avoid loading and collision between two or more classes with the same name. Would make a <textarea> where the user can register all functions of the…
-
0
votes0
answers42
viewsQ: Calculate the page an ID is located on
Assuming I have 10 records and per page shows 3, then the ID 2 will be on the page 1, the ID 7 on the page 3, and so on. In practice I need to access www.dominio.com/lista.php?id=7 page 3, referring…
-
3
votes2
answers257
viewsA: Parameter check on MVC
There are many ways to do it. I will analyze a possibility following @Adriano Godoy’s proposal, not that it is wrong, but it is just simplistic taking into account a bool return in case of failure…
-
3
votes1
answer105
viewsQ: Group on an equal footing
I need to group the result when there are equal records, regardless of the order, whenever the same colors are chosen - group the colors and the users. I need to produce an output like the one…
-
1
votes1
answer337
viewsA: URL Friendly by title
It may be that your 'problem' is more a project issue. Note that your permission array does not form combinations, with this you need to get the 1st bar that corresponds to a file that will scan bar…
-
0
votes0
answers55
viewsQ: Create function for formatting from (X-1, X-2, X-3) to ('X-1', 'X-2', 'X-3')
I have a query that returns some char type keys like this X-1, X-2, X-3. The problem is that now I need to use with where chaves in( ... ) and would have to format the values to 'X-1', 'X-2', 'X-3'.…
-
4
votes1
answer1365
viewsQ: Countdown in two tables
I’m having trouble counting items pertaining to neighborhoods. I need to list all the neighborhoods of the city X and show the items available cars and motorcycles. In the example I only used one…
-
4
votes4
answers53244
viewsA: Different ways to count record numbers in Mysql
Response based on Ricardo’s comment on Big’s response. If you want to return a record limit and know the total how you used: SELECT count(nome),duracao FROM produtos, as an alternative, I think in…
-
1
votes4
answers428
viewsQ: Make SELECT return data in default language when no translation can be found
I’m building a multi-language base. I have a select with the chosen language, but there is no guarantee that 100% of the content is translated, so I need to do a sort of or to the default language…
mysqlasked Papa Charlie 8,721 -
3
votes1
answer1806
viewsA: Pagination, Count to calculate limit and offset by MYSQL
I’ve been looking for a solution and found sql_calc_found_rows and found_rows(). In the example I used in the question, basically it makes the calculation based on the total number of records found…
mysqlanswered Papa Charlie 8,721 -
3
votes1
answer1806
viewsQ: Pagination, Count to calculate limit and offset by MYSQL
I have a query with 7 relationships in a relatively large table, and the list of records uses the total of records as the basis, so it would be a query to calculate the total and another to display…
mysqlasked Papa Charlie 8,721 -
1
votes0
answers1859
viewsQ: MYSQL, problem with characters importing csv
I am passing the Maxmind csv database to mysql and some accented characters are giving problem. In Latin appears a ? and in UTF nothing appears. CSV : Östra Frölunda UTF8 : LATIN1: ?stra Fr?lunda I…
-
7
votes4
answers249
viewsA: Most common words among Rows
One way is to take advantage of the array and count the repeated items using array_count_values. You will have an output as follows: Array ( [Maria] => 3 [Joaquina] => 1 [Antonienta] => 1…
-
6
votes2
answers341
viewsA: PHP array for JSON
You are creating an array only with the last item, as the loop overwrites the previously saved item. Create a $arr multidimensional: while ($dados = mysqli_fetch_assoc($query)) { $arr[] = array(…
-
1
votes4
answers958
viewsA: How to display information (domain name) using PHP?
My proposal is something more dynamic using SERVER_NAME to identify the URL TLD and keep the links in the same domain or force to another domain. Basically, if you want to point the link to another…
phpanswered Papa Charlie 8,721