Jump to content

Barand

Moderators
  • Posts

    24,605
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. You could try something like this example <?php if (isset($_GET['ajax'])) { if (rand(0,1)) { exit("Bar Code Incorrect"); } else { exit("Everything OK"); } } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Test</title> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> $().ready( function() { $("#test").click( function() { $.get( "", {"ajax":1}, function(resp) { if (resp=="Bar Code Incorrect") { let err = $("<div>", {"id":"error", "class":"alert alert-warning", "html":resp}) $("#output").html(err) $("#error").fadeOut(4000) } else { $("#output").html(resp) } } ) }) }) </script> <style type='text/css'> .alert { background-color: red; color: white; padding: 16px; } </style> </head> <body> <button id='test'>Test</button> <div id='output'></div> </body> </html>
  2. Before you go any further you should nomalize those skills and not have a comma-separated list. EG +--------------+ +--------------+ | person | | skill | +--------------+ +--------------+ | person_id PK |--+ +--| skill_id PK | | name | | | | skill_name | | etc | | | +--------------+ +--------------+ | | | +-----------------+ | | | person_skill | | | +-----------------+ | +----<| person_id PK | | | skill_id PK |>--+ | date_achieved | +-----------------+ In the SQL tutorial in my signature there is a similar example application which uses pupils/subects rather than person/skills
  3. Did you you mean something like this? $data = [ 'Hot' => [ 'A' => 5, 'B' => 20, 'C' => 15, 'D' => 10, 'E' => 8 ], 'Dead' => [ 'A' => 15, 'B' => 30, 'F' => 55, 'C' => 40, 'G' => 60, ] ]; echo '<pre> BEFORE ' . print_r($data, 1) . '</pre>'; // original array // // GET ALL KEYS // $keys = []; foreach ($data as $k1 => $v1) { $keys = array_merge($keys, array_keys($v1)); } $keys = array_unique($keys); $blank_values = array_fill_keys($keys, null); // // INSERT MISSING KEYS INTO THE SUBARRAYS // foreach ($data as $k => &$subarray) { $subarray = array_merge($blank_values, $subarray); } echo '<pre> AFTER ' . print_r($data, 1) . '</pre>'; // array after processing which gives... BEFORE Array ( [Hot] => Array ( [A] => 5 [B] => 20 [C] => 15 [D] => 10 [E] => 8 ) [Dead] => Array ( [A] => 15 [B] => 30 [F] => 55 [C] => 40 [G] => 60 ) ) AFTER Array ( [Hot] => Array ( [A] => 5 [B] => 20 [C] => 15 [D] => 10 [E] => 8 [F] => [G] => ) [Dead] => Array ( [A] => 15 [B] => 30 [C] => 40 [D] => [E] => [F] => 55 [G] => 60 ) )
  4. https://www.php.net/manual/en/features.file-upload.post-method.php
  5. Then move all the processing to the same place - one or the other
  6. Erm! @gizmola Note that in the English speaking parts of the world we have "speciality" and not "specialty" 😀
  7. You will need to add GROUP BY sch.id
  8. Where does $row get its values?
  9. Perhaps something like this (my identifiers do not exactly match yours) SELECT h.schoolname as home , a.schoolname as away , sch.preview , GROUP_CONCAT(DISTINCT h.name, ', ', h.ht, ' ', h.pos, '; ', h.grade SEPARATOR ' / ' ) as home_team , GROUP_CONCAT(DISTINCT a.name, ', ', a.ht, ' ', a.pos, '; ', a.grade SEPARATOR ' / ' ) as away_team FROM schedule sch JOIN ( SELECT s.schoolname , concat(p.namefirst, ' ', p.namelast) as name , concat(p.feet, '\'', p.inches, '"') as ht , pos.description as pos , g.description as grade , s.school_id FROM school s JOIN player p ON s.school_id = p.schoolid JOIN grade g USING (grade) JOIN position pos USING (position) ) h ON sch.home_id = h.school_id JOIN ( SELECT s.schoolname , concat(p.namefirst, ' ', p.namelast) as name , concat(p.feet, '\'', p.inches, '"') as ht , pos.description as pos , g.description as grade , s.school_id FROM school s JOIN player p ON s.school_id = p.schoolid JOIN grade g USING (grade) JOIN position pos USING (position) ) a ON sch.away_id = a.school_id PS, output home: School 10 away: School 11 preview: Game on! home_team: Andrew Baker, 6'2" Point Guard; JR / Bernard Cook, 6'5" Shooting Guard; JR / Charles Draper, 6'1" Small Forward; JR / David Potter, 6'4" Power Forward; JR / Eric Fletcher, 6'0" Centre; JR away_team: Frank Gardener, 5'11" Point Guard; JR / Graham Hatter, 6'6" Shooting Guard; JR / Harry Joiner, 6'7" Small Forward; JR / Ian Miller, 6'4" Power Forward; JR / Julie Archer, 5'6" Centre; JR
  10. If it's an array, you need print_r(), not echo
  11. With the two tables I suggested included in your query with joins it would be job done.
  12. Is there any relationship between players age and grade (Senior/Junior)?
  13. I'm guessing that queries with expressions like that above, which contain grade references, will have to be editted every year. If that's true, you really should be looking for another way.
  14. Do you have tables for position and grade? +-----------+-------------------+ +-----------+-------------------+ | position | description | | grade | description | +-----------+-------------------+ +-----------+-------------------+ | 1 | Point guard | | 22 | Senior | | 2 | shooting guard | | 23 | Junior | | etc | | etc | +-----------+-------------------+ +-----------+-------------------+
  15. That line is wrong. It should be either <img class="d-block w-100" src="amin/thumb/<?php echo $row['imgpath']; ?>" alt="First slide"> // or <img class="d-block w-100" src="amin/thumb/<?= $row['imgpath']; ?>" alt="First slide">
  16. Plan B... echo '<pre>' . print_r($line_item->price->metadata->keys(), 1) . '</pre>'; echo '<pre>' . print_r($line_item->price->metadata->values(), 1) . '</pre>';
  17. Does this show anything echo '<pre>' . print_r($line_item->price->metadata, 1) . '</pre>';
  18. Not sure - I don't see anything in there
  19. Have you tried $amount_total = $line_item->amount_total; where $line_item is on of your line item objects?
  20. You still are not reading the replies. Re-read your initial post - it is now the code edited by gizmola. It even tells you at the bottom of the post that it was edited by gizmola.
  21. Don't double-post your questions. It wastes our time.
  22. you should not put user-provided data into your sql query strigs. It exposes you to "SQLinjection". Used prepared statements intead https://www.php.net/manual/en/pdo.prepare.php https://www.php.net/manual/en/pdostatement.execute.php The first query "SELECT quantity FROM book ..." gets the quantity then stores that quantity in the variable "$available". If the book id isn't found, fetchColumn() would return "false" hence the intva()l to change that to 0 - if no books or no record I don't want to update).
  23. Your code seems to be assuming that $delete will be "false" if that first select query does not find any results. Wrong. It will be false only if the query fails with an error. Not finding records is not an error. I would use that first select query to find out how many books there were for that id. Here's a PDO example... if ($_SERVER['REQUEST_METHOD']=='POST') { $res = $conn->prepare("SELECT quantity FROM book WHERE idb = ? "); $res->execute( [$_POST['idb'] ] ); $available = intval($res->fetchColumn()); if ($available >= $_POST['quantity'] ) { $res = $conn->prepare("UPDATE book SET quantity = quantity - ? WHERE idb = ? "); $res->execute( [ $_POST['quantity'], $_POST['idb'] ] ); echo "Book/s successfully removed<br>"; } else { echo "There are only $available books in stock<br>"; } // Remove books with zero quantity $count = $conn->exec("DELETE FROM book WHERE quantity = 0"); echo "$count books were removed<br>"; }
  24. To get the most value from this forum it is best to actually read the replies given. Gizmola told you he had corrected your code in the initial post...
×
×
  • 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.