peat Posted February 2, 2007 Share Posted February 2, 2007 Hi, Ive used this php code for years after someone here kindly helped me out. But in the last few months its just stopped working. I know that the login bit works ok so it must be somewhere in this stuff. Can anyone see something that has caused the problem. (What happens is when I type for example "18-07" into the date search box and then i hit the execute button nothing happens now whereas before it would spit out a big table of records within 3 days either side of the 18th.) Thanks in advance. <?php list($day, $month) = explode('-', $query); $query = '2000-'.$month.'-'.$day; //the variable query should now have a date formatted for the mysql query $result = mysql_query("SELECT *, DATE_FORMAT(Date, '%m%d') AS mmdd from Records WHERE DATE_FORMAT(Date, '%m%d') BETWEEN DATE_FORMAT(DATE_SUB('$query', INTERVAL 3 DAY), '%m%d') AND DATE_FORMAT(DATE_ADD('$query', INTERVAL 3 DAY), '%m%d')ORDER BY mmdd", $db) or die(mysql_error()); // keeps getting the next row until there are no more to get while ($row = mysql_fetch_array($result)){ // stores the date in dd-mm format as variable $date2 $date2 = date('j M', strtotime($row['Date'])); echo "<tr><td>".$row['Bird']."</td><td>".$date2."</td><td>".$row['Location']."</td></tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/ Share on other sites More sharing options...
Daney11 Posted February 2, 2007 Share Posted February 2, 2007 Have you updated web-servers? Upgraded the PHP version? Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-175269 Share on other sites More sharing options...
HuggieBear Posted February 2, 2007 Share Posted February 2, 2007 OK, please tell me that you're fully aware this script is only catering for dates in the year 2000! So if you're trying to retrieve something that you expect to be outside that year, that's why you're getting no results. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-175288 Share on other sites More sharing options...
ted_chou12 Posted February 2, 2007 Share Posted February 2, 2007 hey, i tried this: "SELECT info FROM info BETWEEN '$datetime1' AND '$datetime2'" this query format actually worked. Ted Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-175291 Share on other sites More sharing options...
peat Posted February 2, 2007 Author Share Posted February 2, 2007 my web provider did upgrade to php5 but you have to select that so i am still on php4. I didnt realise that about 2000 huggie but its ok as there are records from 1994 so something should come up. ted - where do I put that code? sorry i really am the worlds worst at php Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-175310 Share on other sites More sharing options...
ted_chou12 Posted February 2, 2007 Share Posted February 2, 2007 if your problem is solved, ignore my post, because i think its what you want... Ted Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-175311 Share on other sites More sharing options...
ted_chou12 Posted February 2, 2007 Share Posted February 2, 2007 hold on, let me think.... so if today is Feb 2nd, you want results from Jan 30th to Feb 5th? Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-175312 Share on other sites More sharing options...
peat Posted February 2, 2007 Author Share Posted February 2, 2007 no there is a text box you fill out and then it gives the records from 3 days either side of whatever date you put in. Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-175333 Share on other sites More sharing options...
ted_chou12 Posted February 2, 2007 Share Posted February 2, 2007 for eg. if your date is "2007/02/02", and you want the results from "2007/01/30" to "2007/02/05": <?php //I assume that your date format is "2007/02/02" without the quotation marks //then... $firstdate = strtotime("2007/02/02") - 259200;//you get 2007/01/30 in strtotime form, convert it: $firstdate = date("Y-m-d", $firstdate);//converted... //do the same with the second date: $seconddate = strtotime("2007/02/02") + 259200;//you get 2007/02/05 in strtotime form, convert it: $seconddate = date("Y-m-d", $seconddate);//converted... //the variable query should now have a date formatted for the mysql query $result = mysql_query("SELECT * FROM table BETWEEN '$firstdate' AND '$seconddate'") or die(mysql_error()); // keeps getting the next row until there are no more to get while ($row = mysql_fetch_array($result)){ // stores the date in dd-mm format as variable $date2 $date2 = date('j M', strtotime($row['Date'])); echo "<tr><td>".$row['Bird']."</td><td>".$date2."</td><td>".$row['Location']."</td></tr>"; I think this would give you what you want. Ted Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-175341 Share on other sites More sharing options...
HuggieBear Posted February 2, 2007 Share Posted February 2, 2007 I didnt realise that about 2000 huggie but its ok as there are records from 1994 so something should come up. No they won't! The only records that will show are those from the year 2000! That's what the hard coded 2000 is doing in this line... $query = '2000-'.$month.'-'.$day; Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-175363 Share on other sites More sharing options...
peat Posted February 3, 2007 Author Share Posted February 3, 2007 Ted that gives me this Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /pages/datesearch.php on line 38 Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-176132 Share on other sites More sharing options...
ted_chou12 Posted February 3, 2007 Share Posted February 3, 2007 I forgot to say, did you change the table in mysql query to the name of your own table? Ted Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-176136 Share on other sites More sharing options...
ted_chou12 Posted February 3, 2007 Share Posted February 3, 2007 sorry, i think this should be the correct format: <?php //I assume that your date format is "2007/02/02" without the quotation marks //then... $firstdate = strtotime("2007/02/02") - 259200;//you get 2007/01/30 in strtotime form, convert it: $firstdate = date("Y-m-d", $firstdate);//converted... //do the same with the second date: $seconddate = strtotime("2007/02/02") + 259200;//you get 2007/02/05 in strtotime form, convert it: $seconddate = date("Y-m-d", $seconddate);//converted... //the variable query should now have a date formatted for the mysql query $result = mysql_query("SELECT * FROM table WHERE date BETWEEN '$datetime1' AND '$datetime2'") or die(mysql_error());//change table and date to your own table name and column name // keeps getting the next row until there are no more to get while ($row = mysql_fetch_array($result)){ // stores the date in dd-mm format as variable $date2 $date2 = date('j M', strtotime($row['Date'])); echo "<tr><td>".$row['Bird']."</td><td>".$date2."</td><td>".$row['Location']."</td></tr>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-176145 Share on other sites More sharing options...
peat Posted February 4, 2007 Author Share Posted February 4, 2007 Hi Ted, It says this now when loading up the page Parse error: syntax error, unexpected $end in /pages/datesearch.php on line 66 Im confused now cus ive just checked and line 66 has nothing in it and its after all the code html or php. Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-176442 Share on other sites More sharing options...
ted_chou12 Posted February 4, 2007 Share Posted February 4, 2007 that means i forgot to add a } at the end, here: <?php //I assume that your date format is "2007/02/02" without the quotation marks //then... $firstdate = strtotime("2007/02/02") - 259200;//you get 2007/01/30 in strtotime form, convert it: $firstdate = date("Y-m-d", $firstdate);//converted... //do the same with the second date: $seconddate = strtotime("2007/02/02") + 259200;//you get 2007/02/05 in strtotime form, convert it: $seconddate = date("Y-m-d", $seconddate);//converted... //the variable query should now have a date formatted for the mysql query $result = mysql_query("SELECT * FROM table WHERE date BETWEEN '$datetime1' AND '$datetime2'") or die(mysql_error());//change table and date to your own table name and column name // keeps getting the next row until there are no more to get while ($row = mysql_fetch_array($result)){ // stores the date in dd-mm format as variable $date2 $date2 = date('j M', strtotime($row['Date'])); echo "<tr><td>".$row['Bird']."</td><td>".$date2."</td><td>".$row['Location']."</td></tr>";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/36750-date-search-used-to-work-now-it-doesnt/#findComment-176581 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.