Hello phpers,
I have this page that I've been SLAVING away at, getting the backend SQL stuff to work (LOAD DATA problems...) Finally I got the backend stuff figured out, and now when I go to search the page contents, I get an intermiittent SQL error. It sometimes appears when the page is loaded fresh, and it sometimes appears when a choice is made on each radio button on the form...but only sometimes! Other times the display works perfect. Any ideas? The code for the page has been pared down for ease of reading.
TIA to all!
Ras.
<?php
function caldate_display($fromdate, $todate = 'null')
{
$format_date = date('F j', strtotime($fromdate));
if ($todate != 'null')
{
$format_date .= '-';
if (date('F', strtotime($fromdate)) == date('F', strtotime($todate)))
{
$format_date .= date('j', strtotime($todate));
}else{
$format_date .= date('F j', strtotime($todate));
}
}
return $format_date;
}
?>
>>snip<<
<h1>Calendar of Events</h1>
<form action="calendar.php" method="post" name="FormName">
<table width="90%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td><input type="radio" name="area" value="east" border="0">East </td>
<td><input type="radio" name="area" value="west" border="0">West </td>
<td><input type="radio" name="area" value="cent" border="0">Central </td>
<td><input type="radio" name="area" value="cana" border="0">Canada </td>
<td><input type="submit" name="submit" onclick="javascript:history.go(0)" value="Display" border="0"></td>
// the page will pass a variable onto itself to pull up the proper data in the SQL query
</tr>
</table>
</form>
<p><?php
// query
$cutoffdate = date('Y-m-d');
if (!isset($area))
{$area = 'east';}else{$area = $HTTP_POST_VARS['area'];}
connect(); // function to connect to DB in include.
$q_calendar = "SELECT e.fromdate, e.todate, e.headline, e.body FROM tbl1 as e
WHERE e.area = '".$area."'
AND e.fromdate > '".$cutoffdate."'
ORDER BY e.fromdate, e.headline";
$r_calendar = mysql_query($q_calendar);
// title section
switch($area)
{
case 'east':
echo "<h1>East<h1>";
break;
case 'west':
echo "<h1>West<h1>";
break;
case 'cent':
echo "<h1>Central<h1>";
break;
case 'cana':
echo "<h1>Canada<h1>";
break;
}
// display contents
while ($row = mysql_fetch_array($r_calendar))
{ echo "<br>";
?></p>
<table width="90%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr height="24">
<td valign="bottom" bgcolor="white" width="10" height="24"><b><font color="#cc6600">:: </font></b></td>
<td align="left" valign="bottom" bgcolor="white" height="24">
<h3><?php echo $row['headline'];?></h3>
</td>
<td align="right" valign="bottom" bgcolor="white" width="25%" height="24"><font color="#cc6666"></font>
<?php
if($row['todate'] != '0000-00-00')
{$dates = caldate_display($row['fromdate'], $row['todate']);}
else{$dates = caldate_display($row['fromdate']);}
echo $dates;?></td>
</tr>
<tr height="1">
<td colspan="2" bgcolor="#ff9966" height="1"></td>
<td bgcolor="#ff9966" width="25%" height="1"></td>
</tr>
<tr height="10">
<td colspan="3" height="10"></td>
</tr>
<tr>
<td colspan="3" align="left" valign="top"><?php
echo $row['body'];?>
</td>
</tr>
</table>
<?php
}
// end of display contents
?>