-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
PHP: GET JSON from URL and structure it in HTML
Barand replied to Zorglub's topic in PHP Coding Help
Example... <?php //The URL of the resource that is protected by Basic HTTP Authentication. $url = 'https://gw.bilinfo.net/listingapi/api/export'; //Your username. $username = 'demo'; //Your password. $password = 'ocfB6XzF73'; //Initiate cURL. $ch = curl_init($url); //Specify the username and password using the CURLOPT_USERPWD option. curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); //Tell cURL to return the output as a string instead //of dumping it to the browser. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Execute the cURL request. $response = curl_exec($ch); //Check for errors. if(curl_errno($ch)){ //If an error occured, throw an Exception. throw new Exception(curl_error($ch)); } ?> <html> <head> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Sample</title> </head> <body> <?= $response; ?> </body> </html> -
I'd just use a loop foreach ($arr['data'] as &$a) { $a['location'] = ucwords(strtolower($a['location'])); } array_map ain't going to play nice with nested arrays.
-
Assign values from the range [.....N] to the vertices of the graph
Barand replied to RohanH's topic in PHP Coding Help
-
Assign values from the range [.....N] to the vertices of the graph
Barand replied to RohanH's topic in PHP Coding Help
vertices values are 3,5,2,4,1 Is there rule for what values are applied to the vertices? I haven't spotted the pattern yet. -
Assign values from the range [.....N] to the vertices of the graph
Barand replied to RohanH's topic in PHP Coding Help
OK, that answers that question. Next, you say you want a function that ... The example you gave has only one sum (31). To find a maximum you need more than one. To get more than one value, something is going to have to vary in value (presumably between fixed limits). So is there something else that you aren't telling us? PS Just seen your latest post. Is that 0.5pt text in your image supposed to be legible? -
Assign values from the range [.....N] to the vertices of the graph
Barand replied to RohanH's topic in PHP Coding Help
-
Assign values from the range [.....N] to the vertices of the graph
Barand replied to RohanH's topic in PHP Coding Help
Your example: A=[2, 2, 1, 3] : : : : B=[1 ,3 ,4, 4] the graph has 4 edges: (2,1),(2,3),(1,4),(2,4) Why is the fourth edge (2,4) and not (3,4) ? -
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);