I can successfully sort 1 HTML table that pulls data from 1 mySQL table.
What I am trying to do is on one page, have three HTML tables, each one pulling data from the same MySQL table Each HTML table displays certain content depending on a field marked yes or no.
Table 1:
Books
Table 2:
Games
Table 3:
Movies
I want to be able to sort Table 1 one by its different fields, but it doesn’t work and I suspect that it’s because I have the other two tables listed with the same case IDs.
<th style="width:250px"><strong><a href="other-items.php?order=oi_name">Name</a></strong></th>
<th style="width:250px"><strong><a href="other-items.php?order=oi_description">Description</a></strong></th>
while ($row = mysql_fetch_array($result)) {
echo '
<tr>
<td style="width:250px">' . $row['oi_name'] . '</td>
<td style="width:250px">' . $row['oi_description'] . '</td>
…
$order = '';
switch($_GET['order'])
{
case 'order':
$order = 'oi_id';
break;
case 'oi_name':
$order = 'oi_name';
break;
This is the whole code for one table:
<?php
// Request the text electronic items
$result = @mysql_query("SELECT oi_name,oi_description,oi_manufacturer,oi_model,oi_serial,oi_purchasedate,oi_manufactureddate,oi_amount,oi_price,oi_retailer,oi_cameraitem,oi_upload1,oi_upload2,oi_upload3 FROM other_items WHERE oi_electronicitem LIKE ('yes') ORDER BY oi_name ASC");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
//creating the table w/ headers
echo '
<table>
<thead>
<tr>
<th style="width:250px"><strong><a href="other-items.php?order=oi_name">Name</a></strong></th>
<th style="width:250px"><strong><a href="other-items.php?order=oi_description">Description</a></strong></th>
<th style="width:150px"><strong><a href="other-items.php?order=oi_manufacturer">Manufacturer</a></strong></th>
<th style="width:250px"><strong><a href="other-items.php?order=oi_model">Model</a></strong></th>
<th style="width:120px"><strong><a href="other-items.php?order=oi_serial">Serial</a></strong></th>
<th style="width:60px"><strong><a href="other-items.php?order=oi_amount">Amount</a></strong></th>
<th style="width:84px"><strong><a href="other-items.php?order=oi_price">Price</strong></th>
<th style="width:110px"><strong><a href="other-items.php?order=oi_purchasedate">Purchased</strong></th>
<th style="width:90px"><strong><a href="other-items.php?order=oi_manufactureddate">Manufactured</strong></th>
<th style="width:90px"><strong><a href="other-items.php?order=oi_retailer">Retailer</strong></th>
</tr>
</thead>';
// Display each item
while ($row = mysql_fetch_array($result)) {
echo '
<tr>
<td style="width:250px">' . $row['oi_name'] . '</td>
<td style="width:250px">' . $row['oi_description'] . '</td>
<td style="width:150px">' . $row['oi_manufacturer'] . '</td>
<td style="width:100px">' . $row['oi_model'] . '</td>
<td style="width:120px">' . $row['oi_serial'] . '</td>
<td style="width:30px">' . $row['oi_amount'] . '</td>
<td style="width:84px">$' . $row['oi_price'] .'</td>
<td style="width:110px">' . $row['oi_purchasedate'] . '</td>
<td style="width:90px">' . $row['oi_manufactureddate'] .'</td>
<td style="width:90px">' . $row['oi_retailer'] .'</td>
</tr>
';
}
echo '</table>';
$order = '';
switch($_GET['order'])
{
case 'order':
$order = 'oi_id';
break;
case 'oi_name':
$order = 'oi_name';
break;
case 'oi_description':
$order = 'oi_description';
break;
case 'oi_manufacturer':
$order = 'oi_manufacturer';
break;
case 'oi_model':
$order = 'oi_model';
break;
case 'oi_serial':
$order = 'oi_serial';
break;
case 'oi_amount':
$order = 'oi_amount';
break;
case 'oi_price':
$order = 'oi_price';
break;
case 'oi_purchasedate':
$order = 'oi_purchasedate';
break;
case 'oi_manufactureddate':
$order = 'oi_manufactureddate';
break;
case 'oi_retailer':
$order = 'oi_retailer';
break;
default:
$order = 'order';
break;
}
;
?>