Jump to content

[SOLVED] Quick Question


paulman888888

Recommended Posts

i have my php script but i would like to order my list relervent to the $_get['order'] (or if there isnt anything in $_get['order'] show all in order with highest score 1st) but i dont know how to input this into my script.

eg something.php?order=ipaddress i would like it to be ordered by ipaddress.

<?php
// Get all the data from the "myscore2" table
$result = mysql_query("SELECT * FROM myscore2 ORDER BY score DESC"); 


echo "<table border='1'>";
echo "<tr><th>ID</th><th>Name</th><th>Score</th><th>Ipaddress</th><th>Game id</th><th>The Date</th><th>Mode</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr>\n";
echo "<td><a href='delete.php?id=".$row['id']."'>".$row['id']."</a></td>\n";
echo "<td>".$row['name']."</td>\n";
echo "<td>".$row['score']."</td>\n";
echo "<td>".$row['ipaddress']."</td>\n";
echo "<td>".$row['gameid']."</td>\n";
echo "<td>".$row['thedate']."</td>\n";
echo "<td>".$row['mode']."</td>\n";
echo "</tr>\n"; 
} echo "</table>";
?>

 

Thankyou

Link to comment
https://forums.phpfreaks.com/topic/108715-solved-quick-question/
Share on other sites

<?php
// Get sort method
$sort = isset($_GET['order']) ? mysql_real_escape_string($_GET['order']) : 'score';
// Get all the data from the "myscore2" table
$result = mysql_query("SELECT * FROM myscore2 ORDER BY `{$sort}` DESC"); 


echo "<table border='1'>";

Im afraid im not even going to bother to read your 'Quick question'. Your last one wasn't, so i've no reason to assume this one is.

 

Please make the effort to give a more discriptive title to the problem if you'd like me to make the effort to answer it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.