-
Posts
24,606 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
input +----+---------------+----------+-------+---------------------+ | id | license_plate | car_bike | price | create_date | +----+---------------+----------+-------+---------------------+ | 1 | BA12ECD | 1 | 5.50 | 2021-08-21 08:09:51 | | 3 | DA12ECD | 1 | 8.50 | 2021-08-21 08:09:51 | | 6 | GA12ECD | 1 | 5.50 | 2021-08-21 08:09:51 | | 7 | HA12ECD | 1 | 8.50 | 2021-08-21 08:09:51 | | 2 | | 2 | 1.50 | 2021-08-21 08:09:51 | | 4 | | 2 | 1.50 | 2021-08-21 08:09:51 | | 5 | | 2 | 1.50 | 2021-08-21 08:09:51 | | 8 | BB12ECD | 1 | 5.50 | 2021-08-22 08:09:51 | | 10 | DB12ECD | 1 | 5.50 | 2021-08-22 08:09:51 | | 13 | GB12ECD | 1 | 9.50 | 2021-08-22 08:09:51 | | 14 | HB12ECD | 1 | 5.50 | 2021-08-22 08:09:51 | | 9 | | 2 | 1.50 | 2021-08-22 08:09:51 | +----+---------------+----------+-------+---------------------+ query SELECT date(create_date) as parking_date , car_bike , count(*) as num , sum(price) as tot FROM tb_parking_group GROUP BY parking_date, car_bike WITH ROLLUP; output +--------------+----------+-----+-------+ | parking_date | car_bike | num | tot | +--------------+----------+-----+-------+ | 2021-08-21 | 1 | 4 | 28.00 | | 2021-08-21 | 2 | 3 | 4.50 | | 2021-08-21 | NULL | 7 | 32.50 | <-- day subtotal | 2021-08-22 | 1 | 4 | 26.00 | | 2021-08-22 | 2 | 1 | 1.50 | | 2021-08-22 | NULL | 5 | 27.50 | <-- day subtotal | NULL | NULL | 12 | 60.00 | <-- total +--------------+----------+-----+-------+
- 1 reply
-
- 1
-
-
fill array with " " to avoid "undefined index" errors?
Barand replied to ChenXiu's topic in PHP Coding Help
If you do want to replace null values with, say, '' (an empty string), then you could do this (usng my above array)... $myarr = array_map('denullify', $myarr); function denullify($v) { return $v ?? ''; } -
fill array with " " to avoid "undefined index" errors?
Barand replied to ChenXiu's topic in PHP Coding Help
Not sure what you are doing with your array to get those undefined index errors. This code doesn't output much but it doesn't give undefined index errors... $myarr = [ 'a' => null, 'b' => null, 'c' => null ]; echo $myarr['a']; echo $myarr['b']; echo $myarr['c']; -
my website this option show - SITE ERROR: MISSING
Barand replied to shahnawaz36's topic in PHP Coding Help
The Force, you should use. -
JSON into CSV : most efficient for large files?
Barand replied to ChenXiu's topic in PHP Coding Help
Consider 3 things The amount of money saved by shaving a few millisecs off the execution time The cost of your time spent trying to shave those few millisecs off the execution time. Is it worth it? -
Rearranging your query to line up the fields with the values... $query = "insert into data (user_id, ??? d_name, manner_death, place_death ,nok, rel_nok, morgue_att, tag_num, treatment) values ('$user_id','$user_name', '$d_name'.'$manner_death','$place_death','$nok','$rel_nok','$morgue_att','$tag_num','$treatment')"; Whether you chage to PDO (recommended) or stay with mysqli, use prepared statements. Don't put data values into the query string. Putting this line of code before you connect the database will get it to report mysql errors... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
-
JSON into CSV : most efficient for large files?
Barand replied to ChenXiu's topic in PHP Coding Help
Decode to an array. fputcsv() doesn't play nice with objects. Then $fp = fopen( 'csv_file.csv' , 'w' ); foreach( $result['content'] as $i ) { fputcsv( $fp , $i ); } fclose($fp); -
Do you mean something like this? <?php // get the "name" headings that you need for the columns // and also use them as keys in a "template" array // $res = $db->query("SELECT DISTINCT name FROM dataset ORDER BY name "); $names = $res->fetchAll(); $heads = array_column($names, 'name'); $temp = array_fill_keys($heads, ''); $table_header = "<tr><td></td><td class='thead'>Result</td><td class='thead'>" . join("</td><td class='thead'>", $heads) . "</td></tr>\n"; // now get the data // store in an array by "id" // witd subarrays for each name $res = $db->query("SELECT id , edate , result , name , nos FROM maintab m JOIN dataset d ON m.id = d.mid ORDER BY id "); $data = []; foreach ($res as $r) { if (!isset($data[$r['id']])) { $data[$r['id']] = [ 'edate' => $r['edate'], 'result' => $r['result'], 'names' => $temp // the template array from earlier ]; } $data[$r['id']]['names'][$r['name']] = $r['nos']; // put value in tempate array } // now we simply output data array into html table rows $tdata = ''; foreach ($data as $row) { $tdata .= "<tr><td>{$row['edate']}</td><td>{$row['result']}</td><td>" . join('</td><td>', $row['names']) . "</td></tr>\n"; } ?> <html> <head> <title>Example</title> <style type='text/css'> td { padding: 4px 10px; } .thead { font-weight: 600; border-top: 1px solid gray; border-bottom: 1px solid gray; } </style> </head> <body> <table> <?= $table_header ?> <?= $tdata ?> </table> </body> </html> OUTPUT [edit] PS Sorry about the data typo. That's what happens when people post pictures instead of copyable text.
-
With an SQL SELECT query with a relevant WHERE clause.
-
-
No, but nor could I see any difference by having it there.
-
This is the closest I could get <html> <head> <style type='text/css'> body { background-color: black; color: #80FF80; } textarea { font-family: monospace; font-size: 18pt; background-color: black; color: #80FF80; border: 1px solid gray; word-break: break-all; margin: 24px; } </style> </head> <body> <textarea cols='43' rows='10'></textarea> </body> </html> giving
-
-
Send an array of parameters instead of lots of individual ones, or you can use the splat (ellipsis) operator (see variadic functions here)
-
Break tags!. That's why I asked you to use a textarea. Break tags are causing the problem. You remove the newline characters but the break tags will make it look as though they are still there when you output to the browser. Don't store break tags in your data, just the newline characters. If you want line breaks in the browser output, add the break tags when you output to the browser with nl2br()
-
Out of curiosity, what do you see if you output them into textareas. If my $row['content'] contains "abc\ndef\nghi", I see ... if I use this code ... $content = str_replace(["\r", "\n"], "", $row['content']); echo "<textarea>{$row['content']}</textarea><br>"; echo "<textarea>$content</textarea><br>";
-
https://dev.mysql.com/doc/refman/5.7/en/blob.html
-
Define the combination of fields as UNIQUE, for example to ensure domain/name are unique ALTER TABLE `cookies` ADD UNIQUE INDEX (domain, name);
-
Which field/s determine if a cookie exists or not? I would guess at domain/name
-
Alter existing code to return second-greatest value (MAX function)
Barand replied to taranator's topic in PHP Coding Help
Sort into descending order Get the second element. -
You are doing it backwards. You need to insert but if it does exist then update instead. INSERT INTO tablename ( ... ) VALUES (...) ON DUPLICATE KEY UPDATE .... https://dev.mysql.com/doc/refman/5.7/en/insert.html
-
prevent empty data from inserting into my database.
Barand replied to sashavalentina's topic in PHP Coding Help
if () is the construct that springs to mind. -
prevent empty data from inserting into my database.
Barand replied to sashavalentina's topic in PHP Coding Help
Then don't insert them. -
phpinfo() will tell you which folder is defined (in php.ini file) as your extensions folder. You will find it in the "Core" section of the output. That is where your extension files need to be.
-
I find it comforting to know that it will try.