I have a web form:
<form method=post action="timesheet_view2.php">
<table width="760" border="0" cellspacing="3" cellpadding="3" align="left">
<tr>
<td width="200" class="heading3">Staff Name</td>
<td width="560" class="heading4"><SELECT multiple NAME="name">
<option>jamesf4218</option>
<option>Pete</option>
<option>Alex Warbler</option>
</SELECT></td></tr>
<tr>
<td width="200" class="heading3">Job Number</td>
<td width="560" class="heading4"><select multiple name="jobnumber">
<option>acd000</option>
<option>acd001</option>
<option>CAU032/401</option>
<option>MOT023/102</option>
</select>
</td>
</tr>
<tr>
<td width="200" class="heading3">Client</td>
<td width="560" class="heading4"><select multiple name="client">
<option>foo</option>
<option>blah</option>
<option>meep</option>
</td>
</tr>
<tr>
<td width="200" class="heading3">Description of Job/Task</td>
<td width="560" class="heading4">
<textarea cols="19" rows="5" name="description">
</textarea>
</td>
</tr>
<tr>
<td width="200" class="heading3">Stage</td>
<td width="560" class="heading4"><select multiple name="stage">
<option>N/A</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select></td>
</tr>
<tr>
<td width="200"class="heading3">Start Date</td>
<td width="560" class="heading4">
<input type="text" value="15-05-03" size=12 name="firstdate"></td>
</tr>
<tr><td width="200"class="heading3">Finish Date</td><td width="560" class="heading4">
<input type="text" size=12 name="lastdate" value="15-05-03"></td>
</tr>
<tr>
<td width="200" class="heading3">Time (in Hrs i.e 4 or 4.5)</td><td width="560" class="heading4">
<input type=text name=timetaken size=12></td>
</tr>
<tr>
<td>
<input class="button" type="submit" value="Submit..."></td>
</tr></table>
<br clear=all>
</form>
</table>
When the user chooses their criteria and click submit, the following script searches the database and brings up the records based on the criteria.
function englishToAmericanDate($str)
{
$elements = explode("-", $str);
$americandate = $elements[2]."-".$elements[1]."-".$elements[0];
return $americandate;
}
$americandate = englishToAmericanDate($firstdate);
$americandate2 = englishToAmericanDate($lastdate);
$db = mysql_connect("localhost", "root"
;
mysql_select_db("acwh",$db);
if ($name == ""
{$name = '%';}
if ($jobnumber == ""
{$jobnumber = '%';}
if ($client == ""
{$client = '%';}
if ($description == ""
{$description = '%';}
if ($stage == ""
{$stage = '%';}
if ($timetaken == ""
{$timetaken = '%';}
$result = mysql_query ("SELECT * FROM timesheets WHERE name LIKE '%$name%' AND jobnumber LIKE '%$jobnumber%' AND client LIKE '%$client%' AND description LIKE '%$description%' AND stage LIKE '%$stage%' AND timetaken LIKE '%$timetaken%' AND entrydate BETWEEN '".$americandate."' AND '".$americandate2."' order by entrydate desc",$db);
if ($myrow = mysql_fetch_row($result)) {
do {
echo "<table width=\"760\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\" align=\"left\">
<tr><td nowrap width=\"120\" class=\"nound2\">",$myrow[1], "</td><td nowrap width=\"100\" class=\"nound2\">",$myrow[2], "</td>
<td nowrap width=\"120\" class=\"nound2\">",$myrow[3], "</td><td nowrap width=\"220\" class=\"nound2\">",$myrow[4], "</td><td nowrap width=\"50\" class=\"nound2\">",$myrow[5], "</td><td nowrap width=\"85\" class=\"nound2\">",$myrow[6], "</td><td nowrap width=\"65\" class=\"nound2\">",$myrow[7], "</td></tr></table><br clear=all>";
$sum += $myrow[7];
} while($myrow = mysql_fetch_row($result));
} else {print "<font color=\"red\">Sorry, no records were found!</font><br>";}
echo "<table width=\"760\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\" align=\"left\"><tr><td colspan=\"2\"><hr color=\"#003366\"></td></tr><tr><td nowrap valign=\"top\" align=\"right\" width=\"740\">The total number of hours is</td><td nowrap valign=\"top\" class=\"nound3\" align=\"right\" width=\"20\"> ", $sum, "</td></tr></table>";
This all works fine. However, if the user tries to choose multiple selections in the same field on the form, it doesn't work. For example, if the users chooses jamesf4218 only, the computer returns all records for jamesf4218. But if the user chooses jamesf4218 and Pete then it just returns the records for pete.
How do I change this please?
Many thanks
James
<form method=post action="timesheet_view2.php">
<table width="760" border="0" cellspacing="3" cellpadding="3" align="left">
<tr>
<td width="200" class="heading3">Staff Name</td>
<td width="560" class="heading4"><SELECT multiple NAME="name">
<option>jamesf4218</option>
<option>Pete</option>
<option>Alex Warbler</option>
</SELECT></td></tr>
<tr>
<td width="200" class="heading3">Job Number</td>
<td width="560" class="heading4"><select multiple name="jobnumber">
<option>acd000</option>
<option>acd001</option>
<option>CAU032/401</option>
<option>MOT023/102</option>
</select>
</td>
</tr>
<tr>
<td width="200" class="heading3">Client</td>
<td width="560" class="heading4"><select multiple name="client">
<option>foo</option>
<option>blah</option>
<option>meep</option>
</td>
</tr>
<tr>
<td width="200" class="heading3">Description of Job/Task</td>
<td width="560" class="heading4">
<textarea cols="19" rows="5" name="description">
</textarea>
</td>
</tr>
<tr>
<td width="200" class="heading3">Stage</td>
<td width="560" class="heading4"><select multiple name="stage">
<option>N/A</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select></td>
</tr>
<tr>
<td width="200"class="heading3">Start Date</td>
<td width="560" class="heading4">
<input type="text" value="15-05-03" size=12 name="firstdate"></td>
</tr>
<tr><td width="200"class="heading3">Finish Date</td><td width="560" class="heading4">
<input type="text" size=12 name="lastdate" value="15-05-03"></td>
</tr>
<tr>
<td width="200" class="heading3">Time (in Hrs i.e 4 or 4.5)</td><td width="560" class="heading4">
<input type=text name=timetaken size=12></td>
</tr>
<tr>
<td>
<input class="button" type="submit" value="Submit..."></td>
</tr></table>
<br clear=all>
</form>
</table>
When the user chooses their criteria and click submit, the following script searches the database and brings up the records based on the criteria.
function englishToAmericanDate($str)
{
$elements = explode("-", $str);
$americandate = $elements[2]."-".$elements[1]."-".$elements[0];
return $americandate;
}
$americandate = englishToAmericanDate($firstdate);
$americandate2 = englishToAmericanDate($lastdate);
$db = mysql_connect("localhost", "root"

mysql_select_db("acwh",$db);
if ($name == ""

{$name = '%';}
if ($jobnumber == ""

{$jobnumber = '%';}
if ($client == ""

{$client = '%';}
if ($description == ""

{$description = '%';}
if ($stage == ""

{$stage = '%';}
if ($timetaken == ""

{$timetaken = '%';}
$result = mysql_query ("SELECT * FROM timesheets WHERE name LIKE '%$name%' AND jobnumber LIKE '%$jobnumber%' AND client LIKE '%$client%' AND description LIKE '%$description%' AND stage LIKE '%$stage%' AND timetaken LIKE '%$timetaken%' AND entrydate BETWEEN '".$americandate."' AND '".$americandate2."' order by entrydate desc",$db);
if ($myrow = mysql_fetch_row($result)) {
do {
echo "<table width=\"760\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\" align=\"left\">
<tr><td nowrap width=\"120\" class=\"nound2\">",$myrow[1], "</td><td nowrap width=\"100\" class=\"nound2\">",$myrow[2], "</td>
<td nowrap width=\"120\" class=\"nound2\">",$myrow[3], "</td><td nowrap width=\"220\" class=\"nound2\">",$myrow[4], "</td><td nowrap width=\"50\" class=\"nound2\">",$myrow[5], "</td><td nowrap width=\"85\" class=\"nound2\">",$myrow[6], "</td><td nowrap width=\"65\" class=\"nound2\">",$myrow[7], "</td></tr></table><br clear=all>";
$sum += $myrow[7];
} while($myrow = mysql_fetch_row($result));
} else {print "<font color=\"red\">Sorry, no records were found!</font><br>";}
echo "<table width=\"760\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\" align=\"left\"><tr><td colspan=\"2\"><hr color=\"#003366\"></td></tr><tr><td nowrap valign=\"top\" align=\"right\" width=\"740\">The total number of hours is</td><td nowrap valign=\"top\" class=\"nound3\" align=\"right\" width=\"20\"> ", $sum, "</td></tr></table>";
This all works fine. However, if the user tries to choose multiple selections in the same field on the form, it doesn't work. For example, if the users chooses jamesf4218 only, the computer returns all records for jamesf4218. But if the user chooses jamesf4218 and Pete then it just returns the records for pete.
How do I change this please?
Many thanks
James