-
Posts
24,605 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
or go with an approach like this <?php // GET FUNCTION CALLS OUT OF THE WAY $thead = "<tr><th>".implode("</th><th>", array_keys($data[0]))."</th></th>\r\n"; $tdata = ''; foreach($data as $datum){ $tdata .= "<tr><td>".implode("</td><td>", $datum)."</td></tr>\r\n"; } // THEN $html = <<<HTML <table class="$class"> <thead> $thead </thead> <tbody> $tdata </tbody> </table> HTML; ?>
-
And you don't see a problem with that? For example 1 2 3 4 5 6 7 8 9 10 Underline any number above that is both less than 5 and greater than 5
-
I don't speak laravelese but is that query trying to find a date that is both greater than and less than $checkin_date?
-
I have a room booking tutorial here, if it helps.
-
Conspicuously absent is any attempt to use xpath as you were advised. Obviously spoonfeeding is required. Here's my version (slightly different from Requinix's, but not much) $xmlstr = <<<XML <kendisplay> <meta> <request>setData</request> <version>1</version> </meta> <data> <SText id="p1"> <text>test</text> </SText> <SText id="p2"> <text>test</text> </SText> <SText id="ken1"> <text>test</text> </SText> <SText id="wait"> <text>test</text> </SText> </data> </kendisplay> XML; $target_id = 'ken1'; $newtext = 'Updated'; $xml = simplexml_load_string($xmlstr); $path = sprintf("//SText[@id='%s']", htmlspecialchars($target_id) ); $ken = $xml->xpath($path); // find the SText $ken[0]->text = htmlspecialchars($newtext); // update its text $xml->asXML('test.xml'); // output updated xml file test.xml output ... <?xml version="1.0"?> <kendisplay> <meta> <request>setData</request> <version>1</version> </meta> <data> <SText id="p1"> <text>test</text> </SText> <SText id="p2"> <text>test</text> </SText> <SText id="ken1"> <text>Updated</text> </SText> <SText id="wait"> <text>test</text> </SText> </data> </kendisplay>
-
https://www.php.net/manual/en/simplexmlelement.xpath.php
-
How to create a search with multiple tables with php and mysqli
Barand replied to bis_codex's topic in PHP Coding Help
To answer your question I would need to know what tables are in the database and the structures of those tables. -
Using book Learn PHP 8 have an error that is wrong
Barand replied to Markus1954's topic in PHP Coding Help
If you want to cast the result of the method call to boolean, the "bool" needs to be on the right hand side of the assignment. Example ... $a = 5; $b = (bool) $a; var_dump($a); // int(5) var_dump($b); // bool(true) -
PHP: Returning and naming specific fields from a CSV in an array
Barand replied to Sonva's topic in PHP Coding Help
No idea what your csv data looks like, so going to use this (mytest.csv)... ,100,"Cancelled",, ,200,"Active",, ,300,"Pending",, then $fp = fopen('files/mytest.csv', 'r'); while ($row = fgetcsv($fp)) { $data[] = [ 'cost' => $row[1], 'status' => $row[2] ]; } fclose($fp); echo '<pre>' . print_r($data, 1) . '</pre>'; giving Array ( [0] => Array ( [cost] => 100 [status] => Cancelled ) [1] => Array ( [cost] => 200 [status] => Active ) [2] => Array ( [cost] => 300 [status] => Pending ) ) -
I had quick look at TCPDF.php and it looks like it has a page rotation option.
-
Put a "Post-It" note on your pack of #10 envelopes with the message "Other way up"
-
'false' is a string value, not a boolean false. From the PHP manual...
- 1 reply
-
- 1
-
-
Not to mention a complete disregard for the fact that id values should be unique.
-
How do I combine values of same col inside a foreach loop?
Barand replied to imgrooot's topic in PHP Coding Help
Don't use two queries (and two loops). Join to the users table and match on the criteria for accceptance (wallet and active) SELECT e.recipient , e.balance , e.posted_date FROM user_earnings e JOIN users u ON e.recipient = u.user_id AND wallet_address <> '' AND active AND balance > 100 JOIN ( SELECT recipient , MAX(posted_date) as posted_date FROM user_earnings GROUP BY recipient ) latest USING (recipient, posted_date) ; -
How do I combine values of same col inside a foreach loop?
Barand replied to imgrooot's topic in PHP Coding Help
To make what more efficient. You still have told us what you are trying to do. What do the wallets have to do with the balance totals, for instance? -
How do I combine values of same col inside a foreach loop?
Barand replied to imgrooot's topic in PHP Coding Help
No mention of balances over 100 or wallets when I asked what you wanted to do. Is there any relationship between user_id and recipient? -
How do I combine values of same col inside a foreach loop?
Barand replied to imgrooot's topic in PHP Coding Help
I had no intention of rewriting your application - just showing you how to query the data you wanted. -
Need help streamlining multi table select and output
Barand replied to darkone2022's topic in PHP Coding Help
Like this, maybe $res = $con->query("SELECT system_id , status_text_color , status_text , icon_color , status_img , link FROM status ORDER BY system_id "); foreach ($res as $row) { echo <<<OUTPUT <div class="col-xl-3 col-sm-6 grid-margin stretch-card"> <div class="card"> <div class="card-body"> <div class="row"> <div class="col-9"> <div class="d-flex align-items-center align-self-start"> <h6 class="mb-0"><?= $row['system_id']; ?></h6> <h6 class="{$row['status_text_color']} ml-2 mb-0 font-weight-medium">{$row['status_text']}</h6> </div> </div> <div class="col-3"> <div class="{$row['icon_color']}"> <span class="{$row['status_img']}"></span> </div> </div> </div> <h6 class="text-primary font-weight-normal"><a href="{$row['link']}" target="_blank">Access System</a></h6> </div> </div> </div> OUTPUT; } -
Need help streamlining multi table select and output
Barand replied to darkone2022's topic in PHP Coding Help
Could you not simply do $result = $conn->query("SELECT system_id , whatever_else FROM `status` ORDER BY system_id "); foreach ($result) { // get results for output } -
How do I combine values of same col inside a foreach loop?
Barand replied to imgrooot's topic in PHP Coding Help
Assuming the latested posted_date may not be the same for every recipient we first need to know what each recipient's latest date is. This is done with a table subquery... ( SELECT recipient , MAX(posted_date) as posted_date FROM user_earnings GROUP BY recipient ) latest We then query the earnings table joined to this subquery matching on the recipient and date so we only process the earnings with the latest date $res = $db->query("SELECT e.recipient , e.balance , e.posted_date FROM user_earnings e JOIN ( SELECT recipient , MAX(posted_date) as posted_date FROM user_earnings GROUP BY recipient ) latest USING (recipient, posted_date) "); $results = $res->fetchAll(); echo '<pre>' . print_r($results, 1) . '</pre>'; // view results $total_balance = array_sum(array_column($results, 'balance')); // get the total balance printf('$%0.2f', $total_balance) ; //-> $300.00 if you are are not interesting in seeing the individual latest records, you can straight to the total with mysql> SELECT SUM(balance) as total_balance -> FROM user_earnings e -> JOIN -> ( -> SELECT recipient -> , MAX(posted_date) as posted_date -> FROM user_earnings -> GROUP BY recipient -> ) latest USING (recipient, posted_date); +---------------+ | total_balance | +---------------+ | 300.00 | +---------------+ -
How do I combine values of same col inside a foreach loop?
Barand replied to imgrooot's topic in PHP Coding Help
You have shown us several queries that don't give you what you want. Thus we know what you don't want. We need to know what you do want. What output would you want to see from this test table and why... +----+-----------+---------+-------------+ | id | recipient | balance | posted_date | +----+-----------+---------+-------------+ | 1 | 1 | 80.00 | 2022-01-09 | | 2 | 2 | 100.00 | 2022-01-09 | | 3 | 3 | 120.00 | 2022-01-09 | | 4 | 1 | 85.50 | 2022-01-16 | | 5 | 2 | 101.25 | 2022-01-16 | | 6 | 3 | 113.25 | 2022-01-16 | | 7 | 1 | 70.00 | 2022-01-23 | | 8 | 2 | 80.00 | 2022-01-23 | | 9 | 3 | 150.00 | 2022-01-23 | +----+-----------+---------+-------------+ -
How do I combine values of same col inside a foreach loop?
Barand replied to imgrooot's topic in PHP Coding Help
Do you mean SELECT SUM(balance) as total FROM user_earnings; which gives ... -
Why don't you use a php function?