Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Are those arrays coming from database tables?
  2. The mysql function NOW() gives the current datetime. mysql> SELECT timestampdiff(DAY, '2024-01-28 09:41:36', NOW() ) as diff; +------+ | diff | +------+ | 1 | +------+
  3. PHP $created = new DateTime('2024-01-27 09:41:00'); $visited = new DateTime('2024-01-29 09:41:00'); echo $visited->diff($created)->format('%a days'); // 2 days SQL SELECT created , visited , timestampdiff(DAY, created, visited) as days FROM test_1; +---------------------+---------------------+------+ | created | visited | days | +---------------------+---------------------+------+ | 2024-01-27 09:41:00 | 2024-01-29 09:41:00 | 2 | +---------------------+---------------------+------+
  4. Except that trying to execute ini_set('display_startup_errors', '1'); when the code doesn't run because of startup errors, is as much use as a chocolate teapot. It has to be set in the php.ini file.
  5. Have you used the network tab in your browser developer tools to check the ajax responses?
  6. Just as it says on the tin - YOUR connection code should go there
  7. Something like this? CODE <?php include 'db_inc.php'; // YOUR CONNECTION $pdo = pdoConnect('movies'); // CODE GOES HERE ################################################################################ ## PROCESS AJAX REQUESTS ################################################################################ if (isset($_GET['ajax'])) { $res = $pdo->prepare("SELECT m.id as movie_id , m.title , m.image , g.description as genre , CONCAT(m.running_time DIV 60, ' hrs ', m.running_time % 60, ' mins') as running_time , date_format(sg.screen_on, '%W, %D %b') as date , s.name as screen_num , TIME_FORMAT(sg.screen_at, '%H:%i') as start_time FROM screening sg JOIN screen s ON sg.screen_id = s.id JOIN movie m ON sg.movie_id = m.id JOIN genre g ON g.id = m.genre WHERE dayname(screen_on) = :day ORDER BY movie_id, screen_on, sg.screen_at "); $res->execute([ 'day' => $_GET['day'] ]); $data = []; # # Put data into an array with same structure a required output # - array of movies, each movie having arrays of screenings # foreach ($res as $r) { if (!isset($data[$r['movie_id']])) { $data[$r['movie_id']] = [ 'title' => $r['title'], 'image' => $r['image'], 'genre' => $r['genre'], 'runtime' => $r['running_time'], 'screenings' => [] ]; } $data[$r['movie_id']]['screenings'][$r['date']][] = ['start' => $r['start_time'], 'sno' => $r['screen_num'] ]; } exit(json_encode($data)); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta name="generator" content="PhpED 12.0 (Build 12010, 64bit)"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>olumide</title> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> function showScreenings(day) { $("#movie-listings").html("") $.get( "", {"ajax":1, "day":day}, function(resp) { $.each(resp, function(mid, mdata) { let title = `<h2>${mdata.title}</h2><h4 class='w3-text-gray'>${mdata.genre} (${mdata.runtime})</h4>` $("#movie-listings").append(title) $.each(mdata.screenings, function(dt, ddata) { let datesub = `<h3>${dt}</h3>` $("#movie-listings").append(datesub) $("#movie-listings").append("<div class='screenings'") $.each(ddata, function(k, sdata) { let scr = `<div class='screening'><b>${sdata.start}</b><br>${sdata.sno}</div>` $("#movie-listings").append(scr) }) $("#movie-listings").append("</div>") }) }) }, "JSON" ) } </script> <style type='text/css'> .days { padding: 16px; text-align: center; } .screening { width : 20%; display: inline-block; margin-right: 16px; margin-bottom: 8px; padding: 4px; border: 5px solid black; font-size: 9pt; } </style> </head> <body> <nav class="days"> <button onclick="showScreenings('Monday')">Monday</button> <button onclick="showScreenings('Tuesday')">Tuesday</button> <button onclick="showScreenings('Wednesday')">Wednesday</button> <button onclick="showScreenings('Thursday')">Thursday</button> <button onclick="showScreenings('Friday')">Friday</button> <button onclick="showScreenings('Saturday')">Saturday</button> <button onclick="showScreenings('Sunday')">Sunday</button> </nav> <div id='movie-listings'class='w3-content w3-padding w3-card-4'> <!-- LISTINGS GO HERE --> </div> </body> </html>
  8. What about all the other data in your query results - whare should that be shown (if at all)?
  9. An image (or mock-up) of what you do want would be more helpful than an image of what you don't want 🙄
  10. I had in mind something like this... CREATE TABLE `win_log` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) DEFAULT NULL, `won` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `collected` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `idx_win_log_user_id` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Bob (user_id #123) wins on Saturday. He also wins on Sunday. Each time he wins, you record the win with this query (inserting $_SESSION['user_id'] into the table) INSERT INTO win_log (user_id) VALUES (?); So now you have TABLE: win_log +----+---------+---------------------+-----------+ | id | user_id | won | collected | +----+---------+---------------------+-----------+ | 1 | 123 | 2024-01-20 18:53:21 | NULL | | 2 | 123 | 2024-01-21 10:33:45 | NULL | +----+---------+---------------------+-----------+ On Monday he goes to collect his tokens. You check he is allowed to by... SELECT COUNT(*) as tot FROM win_log WHERE user_id = ? AND collected IS NULL; If the returned count is > 0 he can go ahead and collect. You record the collection with... UPDATE win_log SET collected = NOW() WHERE user_id = ? AND collected IS NULL ORDER BY won LIMIT 1; You now have +----+---------+---------------------+---------------------+ | id | user_id | won | collected | +----+---------+---------------------+---------------------+ | 1 | 123 | 2024-01-20 18:53:21 | 2024-01-22 19:01:25 | | 2 | 123 | 2024-01-21 10:33:45 | NULL | +----+---------+---------------------+---------------------+
  11. Perhaps maintain log tables of winners (userID and timestamo) and also log when they claimed their reward. On the page where they collect the reward you would first check if they are allowed to be there (winner and not collected) and, if not, redirect them elsewhere.
  12. The highlighted </div> tags have no corresponding <div> tags... When the page is run, the browser adds five </div> tags at the end to close off unclosed div elements... In addition, your table markup is inconsistent, with some rows having three columns and others only having two.
  13. Use the javascript debugger to step through the code to see if it's doing what you expect and that the variables contain what you expect.
  14. Your HTML markup contains many mis-matched <Div..</DIV> tags. Your JQuery is wrong. For example, this doesn't work - addItem() is not called. const addOrderBtn = $('#add-order-btn'); addOrderBtn.click(function (e) { e.preventDefault(); addItem(); }); It needs to be const addOrderBtn = $('#add-order-btn'); $(addOrderBtn).click(function (e) { // note the $(addOrderBtn) e.preventDefault(); addItem(); }); Use your browser's developer tools to debug your JS code
  15. SELECT ... WHERE term = 'c++'
  16. From the manual... Also I am pretty sure that words of 3 chars or less are ignored.
  17. Have you checked that the image files are in the uploads folder? You have a separate table for weapon images??? Why not store the image file name in the weapon table? +--------------+ +--------------+ | player | | weapon | +--------------+ +--------------+ | player_id | +------| weapon_id | | name | | | name | | weapon_id |------+ | damage | +--------------+ | image_file | | level | +--------------+ SELECT w.image_file , w.name , w.damage , w.level , p.weapon_id IS NOT NULL as equip FROM weapon w LEFT JOIN player p USING (weapon_id) +------------+--------+--------+-------+-------+ | image_file | name | damage | level | equip | +------------+--------+--------+-------+-------+ | knife.jpg | Knife | 50 | 1 | 1 | | seax.jpg | Seax | 100 | 1 | 1 | | katana.jpg | Katana | 200 | 1 | 1 | | pistol.jpg | Pistol | 400 | 2 | 0 | | rifle.jpg | Rifle | 750 | 2 | 0 | | rpg.jpg | RPG | 1000 | 3 | 0 | +------------+--------+--------+-------+-------+
  18. In that case, put a weapon id column in the player table. It's value will either be NULL (no weapon) or the weapon id of their weapon. You get the damage value by joining player table to the weapon table using weapon id.
  19. Are you saying only one weapon at a time can be removed from the armoury, or a player can have only one weapon at a time?
  20. TABLES CREATE TABLE `links` ( +---------+-------------------------------+----------------------------------------------------+ `link_id` int(11) NOT NULL AUTO_INCREMENT, | link_id | url | title | `url` varchar(45) DEFAULT NULL, +---------+-------------------------------+----------------------------------------------------+ `title` varchar(100) DEFAULT NULL, | 1 | https://ektoplazm.com/explore | Ektoplazm - Free music portal and psytrance netlab | PRIMARY KEY (`link_id`), | 2 | http://www.google.com | Google | FULLTEXT KEY `idx_links_url` (`url`,`title`) | 3 | http://yahoo.com | Yahoo | ) ENGINE=InnoDB; +---------+-------------------------------+----------------------------------------------------+ CREATE TABLE `terms` ( +---------+---------+-----------+ `term_id` int(11) NOT NULL AUTO_INCREMENT, | term_id | link_id | term | `link_id` int(11) DEFAULT NULL, +---------+---------+-----------+ `term` varchar(45) DEFAULT NULL, | 1 | 1 | radio | PRIMARY KEY (`term_id`), | 2 | 1 | music | FULLTEXT KEY `idx_terms_term` (`term`) | 3 | 1 | psytrance | ) ENGINE=InnoDB; | 4 | 1 | trance | | 5 | 1 | goa | | 6 | 2 | search | | 7 | 3 | search | | 8 | 3 | engine | | 9 | 3 | yahoo | +---------+---------+-----------+ FULLTEXT SEARCH mysql> SELECT l.link_id -> , l.url -> , l.title -> , t.term -> , SUM(MATCH(t.term) AGAINST('search music' IN BOOLEAN MODE) + MATCH(url, title) AGAINST("yahoo")) as `rank` -> FROM links l -> JOIN terms t ON l.link_id = t.link_id -> WHERE MATCH(t.term) AGAINST('search music' IN BOOLEAN MODE) -> OR MATCH(url, title) AGAINST("yahoo") -> GROUP BY title -> ORDER BY `rank` DESC LIMIT 200; +---------+-------------------------------+----------------------------------------------------+--------+--------------------+ | link_id | url | title | term | rank | +---------+-------------------------------+----------------------------------------------------+--------+--------------------+ | 3 | http://yahoo.com | Yahoo | search | 1.7925547659397125 | | 1 | https://ektoplazm.com/explore | Ektoplazm - Free music portal and psytrance netlab | music | 0.9105787873268127 | | 2 | http://www.google.com | Google | search | 0.4266865849494934 | +---------+-------------------------------+----------------------------------------------------+--------+--------------------+
  21. Have you defined FULLTEXT indexes?
  22. You need to join the two tables on the link_id so you match the terms to their parent link Do you have a specific reason for using a fulltext search? Would a simpler "LIKE" suffice. For example SELECT l.id as linkID , l.url , t.term FROM links l JOIN terms t ON l.id = t.link_id WHERE t.term LIKE '%ine%' OR l.url LIKE '%ine%'; linkID | url | term ----------+----------------+----------------- 2 | page2.php | zine 2 | page2.php | magazine 2 | page2.php | online
  23. I don't understand what you are expecting from that line.
  24. Do you have a question?
  25. If you know the date, you know the day of the week. For example SELECT m.title , s.name as screen , date_format(sg.screen_on, '%W, %D %b') as date FROM screening sg JOIN screen s ON sg.screen_id = s.id JOIN movie m ON sg.movie_id - m.id WHERE dayname(screen_on) = 'Wednesday' ORDER BY screen_on; giving +------------------------+------------+---------------------+ | title | screen | date | +------------------------+------------+---------------------+ | Mission Implausible | Screen One | Wednesday, 17th Jan | | Shaving Ryan's Private | Screen Two | Wednesday, 17th Jan | +------------------------+------------+---------------------+
×
×
  • 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.