I have the following php code which queries a table of my database according to place. The table structure is as follows :
s/n | inventory no | asset no | place
=====+==============+============+=============
1 | 125A | 5245 | London
2 | 1254B | 7545 | London
3 | 128A | 5645 | New York
4 | 254B | 1545 | Tokyo
5 | 6545 | 1456 | Tokyo
And the code:
$location=$_POST['loc'];
foreach ($location as $chk1)
{
echo "<br>";
$sql="SELECT * FROM desktop WHERE Place='$chk1';";
$result=mysql_query($sql);
if($result==null)
{
echo '<script> alert("No entry for location '.$chk1.' anditem '.'desktopreturned");</script>';
continue;
}
$row = mysql_fetch_array($result);
if($row==null)
{
echo '<script>alert("No entry for location '.$chk1.' and item '.'desktop returned");</script>';
continue;
}
mysql_data_seek($result, 0);
?><table border='1' id="desktop" caption=<?php $location ?> >
<tr>
<th>S/N</th>
<th>Inventory No</th>
<th>Asset No</th>
<th>Place</th>
</tr>
<?php
while($row = mysql_fetch_array($result)) {?>
<tr class="alt">
<?php
echo "<td>" . $row['S/N'] . "</td>";
echo "<td>" . $row['Inventory no'] . "</td>";
echo "<td>" . $row['Asset No'] . "</td>";
echo "<td>" . $row['Place'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
Edit : CSS code :
#desktop {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
width: 100%;
border-collapse: collapse;
}
#desktop th {
font-size: 1.1em;
text-align: left;
padding-top: 5px;
padding-bottom: 4px;
background-color: #FFCC33;
color: #ffffff;
}
#desktop td, #desktop th {
font-size: 1em;
border: 1px solid #FFCC33;
padding: 3px 7px 2px 7px;
}
#desktop tr.alt td {
color: #000000;
background-color: #FFFFCC;
}
Here, $location is storing the locations selected in the html form.
I want the returned result of the query for different places to be displayed as a single table. Currently it is displaying different place's result as different tables having their own table headers. I want the returned query to be appended into one variable.