Yikes… First, remove all those 's… You only need one form. Inside your outside of your code.
That will be much easier to read.
Now, this code doesn’t do what you want it to. If you look at where you compare row(1) to date1 and row(1) to date2, the results of these compares do the same thing. They display the exact code after the compare…
So, no matter what date row(1) is equal to they do the same thing. I am assuming you are doing this to get the “FREE” results. Remove them all and the compare and just have: (And, change the “FREE” check…)
echo $row[0] .'<input type="hidden" id="reg" name="reg" value="' . $row[2] . '"><input type="submit" value="More info..." />
So, as posted, your old code becomes this:
<form method="get" action="DAY.php">
<?php
$datesrc = date('Y-m-d', strtotime("-1 days"));
$datesrc2 = date('Y-m-d',strtotime("+6 days"));
$date = date('D, d');
$date1 = date('D, d',strtotime("+1 days"));
$date2 = date('D, d',strtotime("+2 days"));
$date3 = date('D, d',strtotime("+3 days"));
$date4 = date('D, d',strtotime("+4 days"));
$date5 = date('D, d',strtotime("+5 days"));
$date6 = date('D, d',strtotime("+6 days"));
echo '<table border="3"><tr><th>' . $date . '</th><th>' . $date1 .'</th><th>'. $date2 . '</th><th>' . $date3 . '</th><th>' . $date4 . '</th><th>'. $date5 . '</th><th>'. $date6 .'</th></tr>';
$db_host = "localhost";
$db_user = "+++++";
$db_pass = "+++++";
$db_base = "+++++";
$db_server = mysql_connect($db_host, $db_user, $db_pass);
if (!$db_server) die("unable to connect: " . mysql_error());
mysql_select_db($db_base)
or die("Unable to select database: " . mysql_error());
$query = "SELECT veh_reg, DATE_FORMAT(veh_date, '%a, %d'), eas_no FROM daybook_db NATURAL JOIN job_db WHERE veh_date>=('$datesrc') AND veh_date<=('$datesrc2')";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
for ($j = 0 ; $j < $rows ; ++$j)
{
$row = mysql_fetch_row($result);
echo'<tr><td>';
for ($i = 0; $i <= 6; $i++) {
$tempdate = date('D, d',strtotime("+" . $i . " days"));
if ($row[1]==$tempdate) { echo $row[0] .'<input type="hidden" id="reg" name="reg" value="' . $row[2] . '"><input type="submit" value="More info..." /> ;}
else {echo 'FREE';}
}
echo '</td>';
}
?>
</form></tr></table>
You could go one step further and make your heading a loop like
for ($i = 0; $i <= 6; $i++) {
$tempdate = date(‘D, d’,strtotime("+" . $i . " days"));
and loop thru your heading echo’ing something like: echo("
" . $tempdate . " | ’);
This way you would not need to assign all of those $date1-7, etc…
Hope all that helps you. Should make the page a little faster to without the extra forms… Good luck…