Hi, I am trying to workout how I can changed the buttons I have for sorting the fields in the table into hyperlinks. I have worked out how to do one, but what about if there are several forms on the same page?
Thanks
<?php
//Connect to server
$conn = mysql_connect ("localhost", "tatty27", "monkeyboy") or die ("Could not connect to database.");
//connect to database
mysql_select_db("tatty27_customers") or die ("Database does not exist.");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Database Exercise 2.2</title>
<style type="text/css">
body {font-family:Verdana, Geneva, sans-serif;
font-size:16px;
}
</style>
</head>
<body>
<?php
//create table
echo '<table border="1">';
echo '<tr>';
echo '<td nowrap>';
echo "<form method=\"post\" action = \"\">";
echo "<input type=\"submit\" value=\"Sort By Customer ID\" name=\"custID\" /><input type=\"submit\" value=\"Desc\" name=\"custDesc\" />";
echo "</form>";
echo '</td>';
echo '<td nowrap>';
echo "<form method=\"post\" action = \"\">";
echo "<input type=\"submit\" value=\"Sort By Name\" name=\"name\" /><input type=\"submit\" value=\"Desc\" name=\"nameDesc\" />";
echo "</form>";
echo '</td>';
echo '<td nowrap>';
echo "<form method=\"post\" action = \"\">";
echo "<input type=\"submit\" value=\"Sort By Address\" name=\"address\" /><input type=\"submit\" value=\"Desc\" name=\"addDesc\" />";
echo "</form>";
echo '</td>';
echo '<td nowrap>';
echo "<form method=\"post\" action = \"\">";
echo "<input type=\"submit\" value=\"Sort By Postcde\" name=\"postcode\" /><input type=\"submit\" value=\"Desc\" name=\"postDesc\" />";
echo "</form>";
echo '</td>';
echo '<td nowrap>';
echo "<form method=\"post\" action = \"\">";
echo "<input type=\"submit\" value=\"Sort By Telephone\" name=\"telephone\" /><input type=\"submit\" value=\"Desc\" name=\"teleDesc\" />";
echo "</form>";
echo '</td>';
echo '<td nowrap>';
echo "<form method=\"post\" action = \"\">";
echo "<input type=\"submit\" value=\"Sort By Email\" name=\"email\" /><input type=\"submit\" value=\"Desc\" name=\"emailDesc\" />";
echo "</form>";
echo '</td>';
$sql = "SELECT * FROM customers";
$result = mysql_query($sql);
if (isset($_POST['custID'])){
$sql = "SELECT * FROM customers order by customerID";
}else if(isset ($_POST['custDesc'])){
$sql = "SELECT * FROM customers order by customerID DESC";
}else if(isset ($_POST['name'])){
$sql = "SELECT * FROM customers order by name";
}else if(isset ($_POST['nameDesc'])){
$sql = "SELECT * FROM customers order by name DESC";
}else if(isset ($_POST['address'])){
$sql = "SELECT * FROM customers order by address";
}else if(isset ($_POST['addDesc'])){
$sql = "SELECT * FROM customers order by address DESC";
}else if(isset ($_POST['postcode'])){
$sql = "SELECT * FROM customers order by postcode";
}else if(isset ($_POST['postDesc'])){
$sql = "SELECT * FROM customers order by postcode DESC";
}else if(isset ($_POST['telephone'])){
$sql = "SELECT * FROM customers order by telephone";
}else if(isset ($_POST['teleDesc'])){
$sql = "SELECT * FROM customers order by telephone DESC";
}else if(isset ($_POST['email'])){
$sql = "SELECT * FROM customers order by email";
}else if(isset ($_POST['emailDesc'])){
$sql = "SELECT * FROM customers order by email DESC";
}
$result = mysql_query($sql);
//repeat loop for each row of results returned
while ($row = mysql_fetch_array($result)or die(mysql_error())){
//enter returned values into table
echo "<tr><td>$row[customerID]</td>".' '."<td>$row[name]</td>".' '."<td>$row[address]</td><td>$row[postcode]</td>".' '."<td>$row[telephone]</td>".' '."<td>$row[email]</td><br />";
}
echo '</td>';
echo '</tr>';
echo'<table>';
?>
</body>
</html>