peat Posted July 30, 2010 Share Posted July 30, 2010 Hi, In 2005 I got help on this forum to write some php code that would return results based on the date input +-3 days. It worked at the time but then it stopped working and I left it until now. Im now updating the database and would love for this query to work again. If anyone can tell me why this code isnt returning anything I would be extremely grateful <?php $db = mysql_connect("localhost", "xxxxx", "xxxxxx"); mysql_select_db("xxxxxxx", $db); // code checking here // ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Manx bird record search</title> </head> <body> <p align="center"><u><font face="Comic Sans MS" style="font-size: 16pt">Manx records date search</font></u></font></p> <p align="center"> </p> <form method="POST" action=""> <p align="center"> Input date (eg for 18th July type in 18-07 ): <input type="text" name="query"> <input type="SUBMIT" value="Search!"> </form> <div align="center"> <table border=1 cellpadding="3" height="14"><tr> <th bgcolor="#CCCCFF" width="200"><span style="font-weight: 400"> <font face="Comic Sans MS">Bird Name</font></span></th> <th bgcolor="#CCCCFF" width="70"><span style="font-weight: 400"> <font face="Comic Sans MS">Date</font></span></th> <th bgcolor="#CCCCFF" width="200"><span style="font-weight: 400"> <font face="Comic Sans MS">Location</font></span></th></tr> <?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>"; } ?> </table> </div> <p align="center"> </p> <p align="center" style="margin-top: 0; margin-bottom: 0"><font size="2">All records from Manx Ornithological Societies annual "Peregrine" reports 1994-2003.</font></p> <p align="center" style="margin-top: 0; margin-bottom: 0"><font size="2">For details on how to purchase the "Peregrine" reports please click on the "Contact me" link of the website.</font></p> <p align="center" style="margin-top: 0; margin-bottom: 0"> </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/209382-old-code-needs-fixing/ Share on other sites More sharing options...
Maq Posted July 30, 2010 Share Posted July 30, 2010 If anyone can tell me why this code isnt returning anything I would be extremely grateful What do you mean exactly (is there a blank page, no results from your query)? Quote Link to comment https://forums.phpfreaks.com/topic/209382-old-code-needs-fixing/#findComment-1093350 Share on other sites More sharing options...
peat Posted July 30, 2010 Author Share Posted July 30, 2010 yeah you type for example 18-07 in the date search box on the page and then hit the search button , the 18-07 dissappears from the box but nothing appears below where the table of results used to appear. Quote Link to comment https://forums.phpfreaks.com/topic/209382-old-code-needs-fixing/#findComment-1093362 Share on other sites More sharing options...
AbraCadaver Posted July 30, 2010 Share Posted July 30, 2010 An upgrade in PHP turned register_globals off: if(isset($_POST['query'])) { $query = $_POST['query']; list($day, $month) = explode('-', $query); // rest of the php code } Quote Link to comment https://forums.phpfreaks.com/topic/209382-old-code-needs-fixing/#findComment-1093371 Share on other sites More sharing options...
peat Posted July 31, 2010 Author Share Posted July 31, 2010 Cheers Ive changed the code to that but its only returning whatever date I put in the input box +3 days and no actual records. (theres nothing appearing in the bird or location box) Quote Link to comment https://forums.phpfreaks.com/topic/209382-old-code-needs-fixing/#findComment-1093549 Share on other sites More sharing options...
peat Posted August 3, 2010 Author Share Posted August 3, 2010 Anyone know what I should try next? Im not clued up on php coding but was trying to learn. Quote Link to comment https://forums.phpfreaks.com/topic/209382-old-code-needs-fixing/#findComment-1094775 Share on other sites More sharing options...
pengu Posted August 4, 2010 Share Posted August 4, 2010 There are some great tutorials on this website. But if you want to get started and back into it again (I had the same problem) try this website : http://www.w3schools.com/php/default.asp I found it good to get back into PHP Quote Link to comment https://forums.phpfreaks.com/topic/209382-old-code-needs-fixing/#findComment-1094860 Share on other sites More sharing options...
peat Posted August 5, 2010 Author Share Posted August 5, 2010 Cheers Pengu. Ill have a look. Quote Link to comment https://forums.phpfreaks.com/topic/209382-old-code-needs-fixing/#findComment-1095659 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.