Jump to content

Barand

Moderators
  • Posts

    24,602
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. That's like asking if a radio transmitter is better than morse code. AJAX is method of communincation between client (javascript) and the server. JSON is a data format.
  2. Use a recursive function to search subcategories until found (Pseudocode ti illustrate the logic...) function searchCategories (category, id, title) { foreach (category as cat) { if (this has the id we want) set title value else searchCategories(children, id, title) // calls itself to search sub categories end if } } My test... $category = $categories; for ($searchfor = 1; $searchfor <= 8; $searchfor++) { $title='Not found'; searchCategories($category, $searchfor, $title); echo "$searchfor - $title<br>"; } /* RESULTS 1 - Pants 2 - Boots 3 - Leather 4 - Textile 5 - Sneakers 6 - Sort 7 - Balls 8 - Not found */
  3. If you echo '<pre>$json = ', print_r($json, 1), '</pre>'; you get $json = Array ( [terms] => http://www.xe.com/legal/dfs.php [privacy] => http://www.xe.com/privacy.php [from] => USD [amount] => 1.195 [timestamp] => 2021-02-09T16:52:00Z [to] => Array ( [0] => Array ( [quotecurrency] => NGN [mid] => 454.6559871014 ) ) ) Then follow the array keys to the value you want So you need echo $json['to'][0]['mid']; // --> 454.6559871014 [edit] Alternatively foreach ($json['to'] as $price) { printf('%s %0.2f<br>', $price['quotecurrency'], $price['mid'] ); // --> NGN 454.66 }
  4. The "mysql_*" functions were deprecated a decade ago and have been removed from PHP 7. You need to use mysqli or PDO (better).
  5. Why "$$value" ?
  6. Thanks for those beautiful code images. Perhaps I'll hang them on my wall. They're no use for anything alse.
  7. https://www.php.net/manual/en/features.file-upload.php
  8. CREATE TEMPORARY TABLE ( .... )
  9. You're welcome. Good to hear I can make a difference somewhere 🙂
  10. Try doing it as I did.
  11. They have to exist to be output. Now if you'd done as I sugessted last time, and created an "age_group" table, the group would exist. And you are still excluding 80 year olds - do you read replies? SELECT group_name , COUNT(i.id) FROM age_group a LEFT JOIN tb_infected i ON i.age BETWEEN a.lo_age AND a.hi_age GROUP BY age_group_id; +------------+-------------+ | group_name | COUNT(i.id) | +------------+-------------+ | Under 18 | 168 | | 18 - 29 | 116 | | 30 - 39 | 92 | | 40 - 49 | 110 | | 50 - 59 | 109 | | 60 - 69 | 110 | | 70 - 79 | 104 | | 80+ | 0 | +------------+-------------+
  12. Example... <?php if ($_SERVER['REQUEST_METHOD']=='POST') { echo "<b>You selected</b><ul>"; foreach ($_POST['fruit'] as $fruit) { echo "<li>$fruit</li>"; // update database here } echo "</ul><hr>"; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Example</title> </head> <body> <h1>Example</h1> <hr> <form method="POST"> Fruit: <br> <select name="fruit[]" multiple size="10"> <option>Apple</option> <option>Banana</option> <option>Date</option> <option>Kiwi</option> <option>Lemon</option> <option>Melon</option> <option>Orange</option> <option>Pear</option> <option>Quince</option> </select> <br> <input type="submit" name="btnSubmit" value="Submit"> </form> </body> </html>
  13. My car engine was leaking oil, so I've drained out all the oil. That's another problem fixed.
  14. Are you wanting something like this? function golfGroups($players) { $n = count($players); if ($n < 6) return $players; $num_3s = $n%4 ? 4 - $n%4 : 0; $num_remain = $n - $num_3s*3; $fours = array_chunk(array_slice($players, 0, $num_remain), 4); $threes = $num_3s ? array_chunk(array_slice($players, -$num_3s*3), 3) : []; return array_merge($fours, $threes); } ## ## TEST IT ## for ($i=6; $i<=25; $i++) { $p = range(1,$i); $p = array_map( function($v) { return "Player $v";}, $p); // create array of players echo "<h3>$i players</h3>"; echo '<pre>', print_r(golfGroups($p), 1), '</pre>'; echo '<hr>'; }
  15. Name the select "troom[]" so the options are posted as an array Then foreach ($_POST['troom'] as $room) { // save $room }
  16. Then $stmt = mysqli_prepare($link, "SELECT username , verified , email FROM users WHERE id = ? "); mysqli_stmt_bind_param($stmt, "i", $_SESSION['id']); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $username, $verified, $email); mysqli_stmt_fetch($stmt); echo "$username, $email, $verified"; However, I'd recommend using PDO instead of mysqli $stmt = $pdolink->prepare("SELECT username , verified , email FROM users WHERE id = ? "); $stmt->execute([$_SESSION['id']]); $row = $stmt->fetch(); echo "{$row['username']}, {$row['email']}, {$row['verified']}"
  17. When a user logs in, what do you store in $_SESSION so that you know they are logged in, and they can be identified? (ideally, this would be the id of their user record)
  18. What information do you know about the logged in user? (I was assuming you have the email already in the session array, but perhaps it's the username or the id (recommended) ).
  19. So the only condition you are interested in is "WHERE email = ?"
  20. Can we please go back to max-height limitations on code boxes. It's real PITA to have to spend time scrolling through hundreds of lines of code. It's a particilar annoyance when there are also long lines of code which end in the middle of the next county. This means you spend time scrolling down to the bottom so that you can then scroll right then scroll back up to the long line (hoping you scrolled far enough and not too far right) Example here...
  21. Your WHERE clause is suspect. Where username, verified and email are what? And if you know what they are, why the query? What is you query supposed to do? Where is $user defiined. You seem to be missing the steps that bind the result and fetch the data returned by the query.
  22. To get the email from a database you would use a SQL SELECT statement. https://dev.mysql.com/doc/refman/5.7/en/select.html
  23. Why not use Date of Birth <input type="date" required> (You will still need to validate the date after the form is submitted to your php script)
  24. Check for mysql error message to see why it failed
×
×
  • 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.