<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="Select * from gigFinder ". buildsqlstring() . " ORDER BY 'gigDay','gigMonth','gigYear' ASCENDING";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "";
?>
<?
if (isset($_POST['Submit']))
{
buildsqlstring();
}
function buildsqlstring()
{
//arrived here because the form button has been pressed
//incoming wanted variables in the $_POST array are
/*
gigBandName
gigPlay
gigDay
gigMonth
gigYear
gigVenue
gigCounty
gigCountry
*/
//check the POST array for empty strings and build the where code at the same time
extract ($_POST);
if (!empty($gigBandName))
{
$where[] = "`gigBandName`='". mysql_escape_string ($gigBandName) ."'";
}
if (!empty($gigPlay))
{
$where[] = "`gigPlay`='" . mysql_escape_string($gigPlay) ."'";
}
if (!empty($gigVenue))
{
$where[] = "`gigVenue`='".mysql_escape_string($gigVenue)."'";
}
if (!empty($gigCounty))
{
$where[] = "`gigCounty`='".mysql_escape_string($gigCounty)."'";
}
if (!empty($gigCountry))
{
$where[] = "`gigCountry`='".mysql_escape_string($gigCountry)."'";
}
//now check the dates
if (empty($gigDay) || empty($gigMonth) || empty($gigYear))
{
//do nothing as there is a blank
}
else
{
//check that the date is valid
$gigDate = $gigYear."-".$gigMonth."-".$gigDay;
if (strtotime($gigDate) === -1)
{
//do nothing because date is bogus - i.e. 30 February, 2003
}
else
{
//either
$where[] = "`gigDay`='$gigDay' AND `gigMonth` = '$gigMonth' AND `gigYear`='$gigYear'";
}
}
//now assemble the where code
$realwhere = " where ";
$cnt =count($where);
for ($i=0; $i<$cnt; $i++)
{
if($i != ($cnt-1)) //this means it is not the last value
{
$realwhere .= $where[$i] . " AND ";
}
else
{
//this is the last value
$realwhere .= $where[$i];
}
}
if ($cnt === 0)
{$realwhere = "";}
return $realwhere;
}
?>
<html>
<head>
<title>Gig Finder Search Results</title>
</head>
<body>
<b><font face="Arial, Helvetica, sans-serif">Gig Finder Search Results</font></b><br><br>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Phone</font></th>
<th><font face="Arial, Helvetica, sans-serif">Mobile</font></th>
<th><font face="Arial, Helvetica, sans-serif">Fax</font></th>
<th><font face="Arial, Helvetica, sans-serif">E-mail</font></th>
<th><font face="Arial, Helvetica, sans-serif">Website</font></th>
<th><font face="Arial, Helvetica, sans-serif">Edit</font></th>
<th><font face="Arial, Helvetica, sans-serif">Delete</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$gigDay=mysql_result($result,$i,"gigDay");
$gigMonth=mysql_result($result,$i,"gigMonth");
$gigYear=mysql_result($result,$i,"gigYear");
$gigBandName=mysql_result($result,$i,"gigBandName");
$gigVenue=mysql_result($result,$i,"gigVenue");
$gigCountry=mysql_result($result,$i,"gigCountry");
$gigCountry=mysql_result($result,$i,"gigCountry");
$gigTown=mysql_result($result,$i,"gigTown");
$gigPlay=mysql_result($result,$i,"gigPlay");
$gigAdmission=mysql_result($result,$i,"gigAdmission");
$gigStart=mysql_result($result,$i,"gigStart");
$gigRestriction=mysql_result($result,$i,"gigRestriction");
$gigComment=mysql_result($result,$i,"gigComment");
$gigContactEmail=mysql_result($result,$i,"gigContactEmail");
$gigContactWeb=mysql_result($result,$i,"gigContactWeb");
$gigId=mysql_result($result,$i,"gigId");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$gigBandName"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$gigStart"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$gigDay"; ?>/<? echo "$gigMonth"; ?>/<? echo "$gigYear"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$fax"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$gigContactEmail"; ?>">E-mail</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>">Website</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="[URL unfurl="true"]http://members.lycos.co.uk/themalloys/members_area/example/update.php?id=<?[/URL] echo "$gigId"; ?>">Edit</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="[URL unfurl="true"]http://members.lycos.co.uk/themalloys/members_area/example/delete.php?id=<?[/URL] echo "$id"; ?>">Delete</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$gigId"; ?></font></td>
</tr>
<?
++$i;
}
echo "</table>";
?>