Jump to content

Old code needs fixing


peat

Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.