philb Posted January 14, 2016 Share Posted January 14, 2016 Please can anyone help with this? I want to print out my data from NOW for today and the next 3 days (4 days in total). Here's my code so far - which prints everything in the database... $sql = "SELECT dt, people, c_fname, c_lname, c_phone, c_notes, code FROM restaurantbooking_bookings ORDER BY dt ASC"; $result = $conn->query($sql); if ($result-> dt < DateTime.Now) { // output data of each row while($row = $result->fetch_assoc()) { print ' <div class="product_item"> Date/Time: ' . $row["dt"]. ' - Pers: ' . $row["people"]. ' - Name: ' . $row["c_fname"]. ' ' . $row["c_lname"]. ' <br/> Tel: ' . $row["c_phone"]. ' - VCode: ' . $row["code"]. ' <br/> Notes: ' . $row["c_notes"]. '<br/>'; }} else { print "0 results"; Thanks in advance Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted January 14, 2016 Solution Share Posted January 14, 2016 Select the data you want to output with a WHERE clause SELECT dt, people, c_fname, c_lname, c_phone, c_notes, code FROM restaurantbooking_bookings WHERE dt BETWEEN CURDATE() AND CURDATE() + INTERVAL 3 DAY ORDER BY dt Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted January 14, 2016 Share Posted January 14, 2016 (edited) assuming dt is a date field you just need to add a simple WHERE condition to your SQL $sql = <<<SQL SELECT dt, people, c_fname, c_lname, c_phone, c_notes, code FROM restaurantbooking_bookings WHERE dt BETWEEN CURDATE() AND DATE_ADD(CURDATE() INTERVAL 3 DAY) ORDER BY dt ASC SQL; Edit: Missed that you had posted Barand - damn support calls! Edited January 14, 2016 by Muddy_Funster Quote Link to comment Share on other sites More sharing options...
philb Posted January 15, 2016 Author Share Posted January 15, 2016 Thanks to you guys for all of your help!!! Now working perfectly. Simple - but I couldn't see it!!! Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted January 15, 2016 Share Posted January 15, 2016 You're very welcome. We all need another pair of eyes at times, best of luck with the rest of your project. Would you be able to mark the topic as Answered please if you are happy that there is nothing else you need covered on it? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.