Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. 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?
  2. I had no intention of rewriting your application - just showing you how to query the data you wanted.
  3. 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; }
  4. 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 }
  5. 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 | +---------------+
  6. 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 | +----+-----------+---------+-------------+
  7. Do you mean SELECT SUM(balance) as total FROM user_earnings; which gives ...
  8. Why don't you use a php function?
  9. What do you see if you echo $sql; Is there a value at the end where the staff id should be?
  10. No it doesn't. Referencing field names that aren't in the table produces that error.
  11. Looks like you have a second datetime later on in the query (lastRain). You need to quote both.
  12. A date time value is a string and therefore needs to be in quotes VALUES ( '$_DateTime', $_tempf, ... Better still, use prepared queries to protect from SQL injection attacks. Don't put variables in the SQL query string.
  13. Look again at my code.
  14. Curly braces and endif don't play nice together. Use one syntax or the other. <?php if($chk == 0) { ?> <div id='showMe'> <div class="container"> <div class="row" style="color:red; padding-top:6rem; text-align:center;"> <h1>Database Update Failed</h1> </div> </div> </div> <?php } else { ?> <div id='showMe'> <div class="container"> <div class="row" style="padding-top:6rem; text-align:center;" > <h1><center>Database Update Successful</center></h1> </div> </div> </div> <?php } ?> </body> </html>
  15. Can you post the data returned by the api without all the var_dump junk in it? Can you post your code in a reasonably formatted manner?
  16. Where is the value for $userLoggedin coming from?
  17. Example $arr = [ [ 'A', 'Jan. 22, 22'], [ 'B', 'Dec. 25, 21'], [ 'C', 'Feb. 22, 22'], [ 'D', 'Jan. 2, 22'] ]; usort($arr, function($a, $b) { $da = DateTime::createFromFormat('M. j, y', $a[1]); $db = DateTime::createFromFormat('M. j, y', $b[1]); return $db <=> $da; }); echo '<pre>' . print_r($arr, 1) . '</pre>'; outputs Array ( [0] => Array ( [0] => C [1] => Feb. 22 22 ) [1] => Array ( [0] => A [1] => Jan. 22 22 ) [2] => Array ( [0] => D [1] => Jan. 2 22 ) [3] => Array ( [0] => B [1] => Dec. 25 21 ) )
  18. try echo "<a href='$latest_dir $latest_file'><button>"."continue</button></a><br>"; ^ ^ ... adding the single quotes, otherwise the href finishes at the space. (Are you sure you want the space?)
  19. It could've been created in a previous month. ("yydd" occurs 12 times per year if dd <= 28)
  20. COALESCE() comes in useful here SELECT ... FROM tablename WHERE COALESCE(colname, '') = '';
  21. If you do, tell us what your real problem is. At present you are telling us a solution that isn't working - because it's the wrong solution, perhaps?
  22. Use outer double quotes to insert a variable into a string. $cat_list = "<a href='blah'>cat 1</a>, <a href='yadayada'>cat 2</a>"; $cat_color = '#8F1FCF'; $cat_list = str_replace('<a', "<a style='color:$cat_color'", $cat_list);
  23. Barand

    $duration

    SImply by using the fact that there are 60 minutes in an hour and some very basic arithmetic. Therefore 0.67 hrs is 60 * 0.67 minutes (= 40 min) $t = 12.67; printf('%d hrs %d min', intval($t), ($t - intval($t))*60); //--> 12 hrs 40 min
  24. It does center the text, but your inline heading is only as wide as its content (as adding a border shows)
×
×
  • 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.