ORDER by problem
Posted: Mon Nov 14, 2011 4:53 pm
I have this code, I have used html radio buttons, and i want to order each and put the results into a table:
[syntax]<?
$table_name = "players";
$database = "my_roster";
$user = "Shawn";
$pass = "1234";
// Create the connection
$connection = mysql_connect( "localhost", $user, $pass );
$db = mysql_select_db( $database );
$db = @mysql_select_db($database, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name ORDER BY ";<<<<<<<<<<<<<<<<<<<What do I need here to make sure they all get ordered via submit button?
$result = @mysql_query($sql,$connection) or die(mysql_error());
?>
<head><h3>My_roster</h3></head>
<?
echo "<table border='20'>
<tr>
<th>Jersey Number</th><th>Position</th><th>Athlete Name</th><th>Birthday</th><th>Stats</th>
</tr>";
while($field = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $field['mid'] . "</td>";
echo "<td>" . $field['format'] . "</td>";
echo "<td>" . $field['artist_ln'] . "</td>";
echo "<td>" . $field['birthday'] . "</td>";
echo "<td>" . $field['notes'] . "</td>";
echo "</tr>";
}
echo "</table>";
while ($row = mysql_fetch_array($result)) {
$mid = $row['mid'];
$format = $row['format'];
$artist_ln = stripslashes($row['artist_ln']);
$birthday = stripslashes($row['birthday']);
$notes = stripslashes($row['notes']);
$display_block .="<p><strong>$mid</strong> by $artist_ln<br> $notes <em>(birthday:$birthday, position:$format)</em></p>";
}
?>
<html>
<body style="background-color:gainsboro;">
<? echo "$display_block"; ?>
<a href= "myroster.html"> Go Back to Roster<br>
</html>
</body>[/syntax]
Code: Select all
<html>
<title>My Roster</title>
<h1>my_roster</h1>
<form method= "post" action= "showroster.php">
<input type= 'radio' name= "mid" value= 'Jersey Number'>Jersey Number
<input type= 'radio' name= "birthday" value= 'Birthday'>Birthday
<input type= 'radio' name= "artist_ln" value= 'Athletes Name'>Athletes Name
<input type= 'radio' name= "format" value= 'Position'> Position
<p><input type= "submit" name= "submit" value= "order" </p><br>
</html>
</form>[syntax]<?
$table_name = "players";
$database = "my_roster";
$user = "Shawn";
$pass = "1234";
// Create the connection
$connection = mysql_connect( "localhost", $user, $pass );
$db = mysql_select_db( $database );
$db = @mysql_select_db($database, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name ORDER BY ";<<<<<<<<<<<<<<<<<<<What do I need here to make sure they all get ordered via submit button?
$result = @mysql_query($sql,$connection) or die(mysql_error());
?>
<head><h3>My_roster</h3></head>
<?
echo "<table border='20'>
<tr>
<th>Jersey Number</th><th>Position</th><th>Athlete Name</th><th>Birthday</th><th>Stats</th>
</tr>";
while($field = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $field['mid'] . "</td>";
echo "<td>" . $field['format'] . "</td>";
echo "<td>" . $field['artist_ln'] . "</td>";
echo "<td>" . $field['birthday'] . "</td>";
echo "<td>" . $field['notes'] . "</td>";
echo "</tr>";
}
echo "</table>";
while ($row = mysql_fetch_array($result)) {
$mid = $row['mid'];
$format = $row['format'];
$artist_ln = stripslashes($row['artist_ln']);
$birthday = stripslashes($row['birthday']);
$notes = stripslashes($row['notes']);
$display_block .="<p><strong>$mid</strong> by $artist_ln<br> $notes <em>(birthday:$birthday, position:$format)</em></p>";
}
?>
<html>
<body style="background-color:gainsboro;">
<? echo "$display_block"; ?>
<a href= "myroster.html"> Go Back to Roster<br>
</html>
</body>[/syntax]