Jump to content

Barand

Moderators
  • Posts

    24,605
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. You're right, but it won't break anything if it is there. For eaxample <?php $a = [1,2,3,4,5,]; echo '<pre>' . print_r($a, 1) . '</pre>'; ?> outputs Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
  2. foreach ($iterator as $filename => $fileInfo) { Where is the end of that foreach loop supposed to be?
  3. 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; ?>
  4. 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
  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?
  6. I have a room booking tutorial here, if it helps.
  7. 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>
  8. https://www.php.net/manual/en/simplexmlelement.xpath.php
  9. To answer your question I would need to know what tables are in the database and the structures of those tables.
  10. 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)
  11. 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 ) )
  12. I had quick look at TCPDF.php and it looks like it has a page rotation option.
  13. Put a "Post-It" note on your pack of #10 envelopes with the message "Other way up"
  14. Barand

    in_array()

    'false' is a string value, not a boolean false. From the PHP manual...
  15. Not to mention a complete disregard for the fact that id values should be unique.
  16. 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) ;
  17. 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?
  18. 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?
  19. I had no intention of rewriting your application - just showing you how to query the data you wanted.
  20. 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; }
  21. 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 }
  22. 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 | +---------------+
  23. 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 | +----+-----------+---------+-------------+
  24. Do you mean SELECT SUM(balance) as total FROM user_earnings; which gives ...
  25. Why don't you use a php function?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.