On the page that display's everything from the database, I have this coding:
<html><title> Accessory and Item Database</title>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<?php
$db = mysql_pconnect("localhost", "root"
@mysql_select_db("acess",$db);
$q = "SELECT user.username,accessory.* FROM user,accessory WHERE user.userId=accessory.userId ORDER BY item desc";
$result = mysql_query($q) or die(mysql_error().$q);
$num_rows = mysql_num_rows($result);
if($num_rows > 0) {
?>
<center>
<table border=1 width=700 bordercolor="#FFFFFF" cellpadding="4" cellspacing="0">
<tr>
<td width=700 bgcolor="#990000" valign="top" colspan="3"><font size="4" face="Arial, Helvetica, sans-serif" color="#FFFFFF">
Accessory and Item Database</font></td>
</tr>
<tr>
<td width=400 bgcolor="#990000" valign="top"><font size="2" face="Arial, Helvetica, sans-serif" color="#FFFFFF"><b><font size="3">Item</font></b></font></td>
<td width=150 valign="top" bgcolor="#990000"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"><b><font size="3">Serial
Number</font></b></font></td>
<td width=150 bgcolor="#990000"><font size="4" face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF" size="3">On
Loan to</font></b></font></td>
</tr>
<?php
while($myrow = mysql_fetch_array($result)) {
echo " <tr>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["item"]."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["snumber"]."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["username"]."</font></td>
</tr>\n";
}
?>
</table>
</center>
<?php
}
else {
echo "No records were found!\n";
}
?>
</body>
</html>
How can I get the headings of the table (as links) so that when they click on "ITEM" it can reorder them by its name or if they Click on the "SERIAL NUMBER" it can re-order the display by SERIAL Number order?
I was given this as an answer (but im getting an SQL syntax error):
changed
$q = "SELECT user.username,accessory.* FROM user,accessory WHERE user.userId=accessory.userId ORDER BY item desc";
to
$q = "SELECT user.username,accessory.* FROM user,accessory WHERE user.userId=accessory.userId ORDER BY $sort desc";
and added this as a link (to Arrange by Serial Number)
<a href="<? echo $PHP_SELF; ?>?sort=snumber">Serial Number</a>
And the error I get:
You have an error in your SQL syntax near 'desc' at line 1SELECT user.username,accessory.* FROM user,accessory WHERE user.userId=accessory.userId ORDER BY desc
<html><title> Accessory and Item Database</title>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<?php
$db = mysql_pconnect("localhost", "root"
@mysql_select_db("acess",$db);
$q = "SELECT user.username,accessory.* FROM user,accessory WHERE user.userId=accessory.userId ORDER BY item desc";
$result = mysql_query($q) or die(mysql_error().$q);
$num_rows = mysql_num_rows($result);
if($num_rows > 0) {
?>
<center>
<table border=1 width=700 bordercolor="#FFFFFF" cellpadding="4" cellspacing="0">
<tr>
<td width=700 bgcolor="#990000" valign="top" colspan="3"><font size="4" face="Arial, Helvetica, sans-serif" color="#FFFFFF">
Accessory and Item Database</font></td>
</tr>
<tr>
<td width=400 bgcolor="#990000" valign="top"><font size="2" face="Arial, Helvetica, sans-serif" color="#FFFFFF"><b><font size="3">Item</font></b></font></td>
<td width=150 valign="top" bgcolor="#990000"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"><b><font size="3">Serial
Number</font></b></font></td>
<td width=150 bgcolor="#990000"><font size="4" face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF" size="3">On
Loan to</font></b></font></td>
</tr>
<?php
while($myrow = mysql_fetch_array($result)) {
echo " <tr>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["item"]."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["snumber"]."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["username"]."</font></td>
</tr>\n";
}
?>
</table>
</center>
<?php
}
else {
echo "No records were found!\n";
}
?>
</body>
</html>
How can I get the headings of the table (as links) so that when they click on "ITEM" it can reorder them by its name or if they Click on the "SERIAL NUMBER" it can re-order the display by SERIAL Number order?
I was given this as an answer (but im getting an SQL syntax error):
changed
$q = "SELECT user.username,accessory.* FROM user,accessory WHERE user.userId=accessory.userId ORDER BY item desc";
to
$q = "SELECT user.username,accessory.* FROM user,accessory WHERE user.userId=accessory.userId ORDER BY $sort desc";
and added this as a link (to Arrange by Serial Number)
<a href="<? echo $PHP_SELF; ?>?sort=snumber">Serial Number</a>
And the error I get:
You have an error in your SQL syntax near 'desc' at line 1SELECT user.username,accessory.* FROM user,accessory WHERE user.userId=accessory.userId ORDER BY desc