Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. In my query, change all "UNION" to "UNION ALL"
  2. http://lmgtfy.com/?q=php+search+pagination+tutorial
  3. without knowing the methods inside your sql class we would only be guessing
  4. Have you fixed the issues you have been told about already? The same goes for sex as it did for district. If "all" sexes are required you can leave it out of the query
  5. I agree with Kicken. Store the time (and duration if it can vary for various tasks) and check if the current time is beyond the stored time plus the duration. If it isn't, make the user wait. Here's an example (requires img_bar.php attached) <?php session_start(); if (isset($_GET['btnSub']) && $_GET['btnSub']=='Upgrade') { $t = time(); $d = $_GET['duration']; // seconds } else { $t = $d = 0; } $_SESSION['upgradetime'] = $t; $_SESSION['upgradeduration'] = $d; // seconds ?> <html> <head> <meta name="generator" content="PhpED 12.0 (Build 12010, 64bit)"> <title>Example delay</title> <link rel="shortcut icon" href=""> <style type="text/css"> img#bar, input#btnSub { visibility: hidden; } </style> <script type="text/javascript" src="../jquery-1.10.2.js"></script> <script type="text/javascript"> var upgradetime = <?php echo $_SESSION['upgradetime'] ?>; var duration = <?php echo $_SESSION['upgradeduration']?>; var waiting = false; function bar() { var t = new Date(); var val = (t.getTime()/1000)-upgradetime; if (val < 0) { $("#bar").css("visibility","hidden"); return; } if (val > duration) { $("#bar").css("display","none"); if (waiting) { $("#btnSub").css("visibility","visible"); } return; } waiting = true; $("#bar").css("visibility","visible"); $("#bar").attr("src","img_bar.php?max="+duration+"&val="+val); } $().ready (function() { bar(); setInterval("bar()", 2000); }); </script> </head> <body> <?php if ($_SESSION['upgradetime'] > 0) { ?> <form id="fm1"> <img src="img_bar.php" id="bar"> <input type='submit' name='btnSub' id='btnSub' value='Continue'> </form> <?php } else { ?> <p>Here goes whatever your page normally does</p> <form> <!-- duration set to 10, 20, 30secs for demo purposes --> Duration<br> <input type='radio' name='duration' value='10'> 10 secs<br> <input type='radio' name='duration' value='20'> 20 secs<br> <input type='radio' name='duration' value='30'> 30 secs<br> <input type="submit" name="btnSub" value="Upgrade"> </form> <?php } ?> </body> </html> img_bar.php
  6. Why the join? You are storing the team names in the matches table according to that data. You should be storing the team ID values
  7. I believe he wants counts of the occurences of each number SELECT colno, num, COUNT(*) AS CT FROM ( SELECT 1 as colno, Number1 as num FROM Draws UNION SELECT 2 as colno, Number2 as num FROM Draws UNION SELECT 3 as colno, Number3 as num FROM Draws UNION SELECT 4 as colno, Number4 as num FROM Draws UNION SELECT 5 as colno, Number5 as num FROM Draws UNION SELECT 6 as colno, Number6 as num FROM Draws ) as balls GROUP BY colno, num ORDER BY colno, CT DESC
  8. That's because it is 1 mth 0 days 4hrs try echo $d1->diff($d2)->format('%m mths %d days %h hrs %i mins'); //-> 1 mth 0 days 4 hrs 30 mins or echo $d1->diff($d2)->format('%a days %h hrs %i mins'); //-> 31 days 4 hrs 30 mins
  9. or $date_reported = '2013-12-27 10:30:00'; $date_resolved = '2014-01-05 15:00:00'; $d1 = new DateTime($date_resolved); $d2 = new DateTime($date_reported); echo $d1->diff($d2)->format('%d days %h hrs %i mins'); //-> 9 days 4 hrs 30 mins
  10. Amendment to above ^^ Change fetch_assoc() to fetch_row()
  11. Several points worth mentioning with that script. You only want the news_id in that first query so "SELECT news_id FROM ....". Don't use "SELECT * ", select only what you need . A query returning no rows is not an error. Don't run queries inside loops - use a JOIN to retrieve the data with a single query. mysql_ library has been replaced by mysqli_ and will not be available after v5.4 $query = "SELECT n.id , n.title FROM news_to_people np INNER JOIN news n ON np.news_id = n.id WHERE np.people_db_id = $db_id"; $res = $db->query($query); echo "<div>"; while (list($id, $title) = $res->fetch_assoc()) { echo '<ul>'; echo '<l1><a href="article?articleid='.$id.'&name='.$db_name.'">'.$title.'<br></l1>'; echo '</ul>'; } echo '</div>'; // END TO CONTAINER
  12. Barand

    Seat map.

    You don't say what type of seat but it would probably be time-based as well as location-based so you would need a data structure along these lines. +------------+ +-------------+ | seat | | session | +------------+ +-------------+ | seatId |---+ +-----| sessionId | | seat_row | | | | sessionDate | | seat_no | | | | sessionTime | | location | | | +-------------+ +------------+ | | | +---------------+ | | | booking | | | +---------------+ | | | bookingId | | | | sessionId | >-+ +---< | seatId | | status | +---------------+ "Location" in the seat table would, in the case of a theatre, be something like front stalls, balcony etc. You would need to store enough for you calculate the seat position on a map. Say from row and seat number in a simple layout. Example http://forums.phpfreaks.com/topic/284542-allocated-seating-layout-help/?do=findComment&comment=1461646
  13. Not as easy but, in theory, you could apply a similar technique. The searching code above stops when it finds a long row of white pixels. This time you would have to continue until all four top left (x,y) positions were found and stored in an array. You would then do the same for the bottom right positions and pair them off with the top left positions. However in practice you have a problem with the image you posted. If you look at my attached image (which is part of a magnified version of yours) you will see there is no row of white pixels at the bottom of the text box - the text touches the border. One option may be to find the top lefts (where there are white pixels) and assume they are all of a fixed size.
  14. ... you forgot to mention the total lack of indentation and formatting to make it readable (just in case anyone wanted to)
  15. Sorry - should be DAY, not DAYS
  16. try > instead of < and use CURDATE() SELECT COUNT(*) FROM checkout_page WHERE id = 1 AND DATE(checkout_date) > CURDATE() - INTERVAL 7 DAYS
  17. We are not going to do your assignment for you. Google "recursion" - the usual example given is factorials. Ditto factorizing numbers. For the last one use a couple of nested for() loops.
  18. or you can do the date calculation within the query $updateJob = mysql_query("UPDATE jobs SET sent='1' WHERE sent='0' and dateofenquiry <= CURDATE() - INTERVAL 14 DAY ", $conn);
  19. Something like this maybe SELECT f1.origin , f1.destination , '' as via , f1.departure , f1.arrival , f1.flightNo , f1.airline FROM flight f1 WHERE f1.origin='Paris' AND f1.destination = 'Bangkok' AND f1.date = '2014-01-08' UNION SELECT f1.origin , f2.destination , f1.destination as via , f1.departure , f2.arrival , f1.flightNo , f1.airline FROM flight f1 INNER JOIN flight f2 ON f1.destination=f2.origin AND f1.flightno = f2.flightno WHERE f1.origin='Paris' AND f2.destination = 'Bangkok' AND f1.date = '2014-01-08 +--------+-------------+-----------+-----------+----------+----------+---------+ | origin | destination | via | departure | arrival | flightNo | airline | +--------+-------------+-----------+-----------+----------+----------+---------+ | Paris | Bangkok | | 09:00:00 | 12:00:00 | Q123 | Qatar | | Paris | Bangkok | Amsterdam | 09:00:00 | 15:30:00 | Q123 | Qatar | +--------+-------------+-----------+-----------+----------+----------+---------+
  20. What is your current query - the one creating your issue? Do you want to retrieve both the flight via Amsterdam and the direct one just the direct flight just the one via Amsterdam It isn't clear what you want
  21. An id is a unique identifier for a record. It should retain that same id for the whole lifetime of the record. The id should not be reused. What is there about that record that says it must be no 33?
  22. No field terminators? No commas in value?
  23. The smart thing to would be to follow up on the the advice you were given (http://www.php.net/manual/en/security.globals.php) rather than winge and post another topic with the same question
  24. I'm only using partial data but this should give the idea $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $sql = "SELECT prodCat, prodName, prodPrice FROM product ORDER BY prodCat"; $res = $db->query($sql); while ($row = $res->fetch_assoc()) { $products[$row['prodCat']][] = $row; } foreach ($products as $cat => $prodArray) { echo '<h3>' . $cat . ' - ' . count($prodArray) . '</h3>'; foreach ($prodArray as $p) { echo "<div style='border: 1px solid gray; margin-bottom: 10px; padding:5px'> <p>{$p['prodName']}</p> <p>{$p['prodPrice']}</p> </div>"; } }
  25. It would help us greatly to help you if you gave us your table structures and some sample fable data
×
×
  • 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.