hotmert Posted August 16, 2011 Share Posted August 16, 2011 Ok so, I have a database with loads of upcoming events. The events hay and 'id' key byt NOT inputted in sequence, but are sorted by date for output to a listing page. I am attempting to show a snippit from that listing and show on my homepage i.e. now and next events. It kinda worked but now it's not. It seems to show either no next event or the next 'id' event. The first time i wrote and tried the code it worked but now two days later is gone a bit wrong. This is what I have going at the moment to get the now and next onto homepage $sql = "(SELECT date, time, event, bands FROM listings WHERE date = CURDATE() LIMIT 1 ) UNION (SELECT date, time, event, bands FROM listings WHERE date > CURDATE() LIMIT 1 )" or die(mysql_error()); https://www.thefiddlerselbow.co.uk https://thefiddlerselbow.co.uk/gig_guide.php I just noticed at 05:57 GMT that the next event has appeared but its the next id event not date event...Obviously it's using US time....humm So I guess help the code works but a tweak on the code to get it to show the now and next events on date not id would help. Thanks for looking, these forums are so good when your head is full no ideas. Quote Link to comment https://forums.phpfreaks.com/topic/244893-help-displaying-now-next-events-form-sql-database/ Share on other sites More sharing options...
hotmert Posted August 16, 2011 Author Share Posted August 16, 2011 I just checked the database and my script is showing id 59 then id 70 Quote Link to comment https://forums.phpfreaks.com/topic/244893-help-displaying-now-next-events-form-sql-database/#findComment-1257979 Share on other sites More sharing options...
hotmert Posted August 16, 2011 Author Share Posted August 16, 2011 error "The events hay and 'id' key byt NOT inputted in sequence" Should read - The events key is 'id' but the events themselves are not entered in order by date. Quote Link to comment https://forums.phpfreaks.com/topic/244893-help-displaying-now-next-events-form-sql-database/#findComment-1258005 Share on other sites More sharing options...
harristweed Posted August 16, 2011 Share Posted August 16, 2011 I'd try $sql = "(SELECT date, time, event, bands FROM listings WHERE date >= CURDATE() LIMIT 0, 2 )" Quote Link to comment https://forums.phpfreaks.com/topic/244893-help-displaying-now-next-events-form-sql-database/#findComment-1258014 Share on other sites More sharing options...
hotmert Posted August 16, 2011 Author Share Posted August 16, 2011 Just tried that and it did the same thing, however I tried this and at the moment it seems to work. Just added ORDER BY date before the LIMIT 1 $sql = "(SELECT date, time, event, bands FROM listings WHERE date = CURDATE() ORDER BY date LIMIT 1) UNION (SELECT date, time, event, bands FROM listings WHERE date > CURDATE()ORDER BY date LIMIT 1) " Quote Link to comment https://forums.phpfreaks.com/topic/244893-help-displaying-now-next-events-form-sql-database/#findComment-1258144 Share on other sites More sharing options...
harristweed Posted August 16, 2011 Share Posted August 16, 2011 As you are only using one table, you don't need UNION! Quote Link to comment https://forums.phpfreaks.com/topic/244893-help-displaying-now-next-events-form-sql-database/#findComment-1258279 Share on other sites More sharing options...
hotmert Posted August 17, 2011 Author Share Posted August 17, 2011 Yeah it is one table. I could not work out the code to display so I used UNION. By the way today its not working again. It may not always be, that there is something on "today". So show the next date and the next one after that event if the next date is today. Now I'm confused. Quote Link to comment https://forums.phpfreaks.com/topic/244893-help-displaying-now-next-events-form-sql-database/#findComment-1258434 Share on other sites More sharing options...
hotmert Posted August 17, 2011 Author Share Posted August 17, 2011 that should have read "even if the next date is today". My localhost version is working ok. Maybe that code is unstable. Should try work out another way to get the same result. Quote Link to comment https://forums.phpfreaks.com/topic/244893-help-displaying-now-next-events-form-sql-database/#findComment-1258437 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.