andrew_biggart Posted July 24, 2013 Share Posted July 24, 2013 I'm struggling to get my head around the logic of this, and wondering if someone can point me in the right direction. Overview What I'm trying to do is query the database and get all records which have a date which falls within the next week. Can anyone point me in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/280453-getting-the-next-weeks-deadlines-from-the-database/ Share on other sites More sharing options...
andrew_biggart Posted July 24, 2013 Author Share Posted July 24, 2013 I thought this would do it, but it isn't pulling out any records. <?php $today = date("Y-m-d"); $week = date("Y-m-d",strtotime("+1 week")); $sql = " SELECT * FROM jobsT WHERE job_deadline BETWEEN $today AND $week"; $result = mysql_query($sql); ?> Quote Link to comment https://forums.phpfreaks.com/topic/280453-getting-the-next-weeks-deadlines-from-the-database/#findComment-1441913 Share on other sites More sharing options...
andrew_biggart Posted July 24, 2013 Author Share Posted July 24, 2013 (edited) School boy syntax error. It's working now. <?php $today = date("Y-m-d"); $week = date("Y-m-d",strtotime("+1 week")); $sql = " SELECT * FROM jobsT WHERE job_deadline BETWEEN '$today' AND '$week'"; $result = mysql_query($sql); ?> Edited July 24, 2013 by andrew_biggart Quote Link to comment https://forums.phpfreaks.com/topic/280453-getting-the-next-weeks-deadlines-from-the-database/#findComment-1441914 Share on other sites More sharing options...
andrew_biggart Posted July 24, 2013 Author Share Posted July 24, 2013 I'm trying to add an additional parameter to the WHERE statement, which will only select jobs with a status of 'Accepted' and are within the next week. However when I add this parameter, it returns no results. i have checked, and there is definitely jobs which should be show. What am I doing wrong? <?php $today = date("Y-m-d"); $week = date("Y-m-d",strtotime("+1 week")); $sql1 = " SELECT * FROM jobsT WHERE job status = 'Accepted' AND job_deadline BETWEEN '$today' AND '$week'"; $result1 = mysql_query($sql1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/280453-getting-the-next-weeks-deadlines-from-the-database/#findComment-1441946 Share on other sites More sharing options...
PaulRyan Posted July 24, 2013 Share Posted July 24, 2013 You need to put back ticks around the column name as you have a space in its name. `job status` Personally, I replace all spaces with underscores to avoid such errors and looks better in my opinion. Quote Link to comment https://forums.phpfreaks.com/topic/280453-getting-the-next-weeks-deadlines-from-the-database/#findComment-1441948 Share on other sites More sharing options...
andrew_biggart Posted July 24, 2013 Author Share Posted July 24, 2013 Sorry, that's a typo. It's actually job_status. But thats's still not pulling any records through... Quote Link to comment https://forums.phpfreaks.com/topic/280453-getting-the-next-weeks-deadlines-from-the-database/#findComment-1441949 Share on other sites More sharing options...
Solution andrew_biggart Posted July 24, 2013 Author Solution Share Posted July 24, 2013 (edited) I've re-typed it, and it's working now. I think it might have been a caching issue. Dam Google chrome! <?php $today = date("Y-m-d"); $week = date("Y-m-d",strtotime("+1 week")); $sql1 = "SELECT * FROM jobsT WHERE job_status = 'Accepted' AND job_deadline BETWEEN '$today' AND '$week'"; $result1 = mysql_query($sql1); ?> Edited July 24, 2013 by andrew_biggart Quote Link to comment https://forums.phpfreaks.com/topic/280453-getting-the-next-weeks-deadlines-from-the-database/#findComment-1441950 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.