spider661 Posted July 21, 2008 Share Posted July 21, 2008 i have a mysql table with 2 fields one is the player name the other is profile.. in the profile field it holds all info about the player now i can sort this all out and make a new temp table and put all the info in it. player mana hp ac and the new table will now have all that info what i want to do is make like a ranking board where you can look up who is the best on the server based on mana hp or ac and then sort it. and get a nice list.. i know how to do everything but what i don't know how to do is take the info out of the new temp table put it into an array delete the temp table them pull the info from the array when called. this is how i would do it if i was calling the info from the table directly every time but i want to delete the temp table and use an array encase some one else laded the page at the same time i don't want it making a new temp table while someone else is reading from it so i want to put the info in an array and then sort it and delete the table. anyways here is how i do it without the array can someone help me make the array and work it into this? if(isset($_GET['c'])) $c = $_GET['c']; else $c = 0; if(isset($_GET['l'])) $l = $_GET['l']; else $l = '0'; if(isset($_GET['o'])) $o = $_GET['o']; else $o = '0'; if(isset($_GET['sort'])) $sort = $_GET['sort']; else $sort = 'hp'; $numToDisplay = 20; $c = preg_replace("/;/", "", $c); $l = preg_replace("/;/", "", $l); $o = preg_replace("/;/", "", $o); //$n = preg_replace("/;/", "", $n); mysql_connect($host, $dbuser, $dbpass); mysql_select_db("$db") or die(mysql_error()); if($o != $l) { $c = 0; $o = $l; } if($c == 0 && $l == 0 && $o ==0) { //build temp table } if($l != '0') $sql = "SELECT id, name, hp, mana, ac FROM character_ WHERE character_.class = '$l' ORDER BY $sort LIMIT $c, $numToDisplay;"; else $sql = "SELECT id, name, hp, mana, ac FROM character_ ORDER BY $sort LIMIT $c, $numToDisplay;"; $results = mysql_query("$sql"); $numChars = mysql_num_rows($results); for($i = 0; $i < $numChars; $i++) { $row = mysql_fetch_array($results); $name = $row['name']; $hp = $row['hp']; $mana = $row['mana']; $ac = $row['ac']; echo '<table width="100%" border="1" cellspacing="0" cellpadding="0">'; echo '<tr>'; echo '<th><a href=\"test.php?l=$l&c=$newC&o=$o&sort=name\">Name</a></th>'; echo '<th><a href=\"test.php?l=$l&c=$newC&o=$o&sort=hp\">HP</a></th>'; echo '<th><a href=\"test.php?l=$l&c=$newC&o=$o&sort=mana\">Mana</a></th>'; echo '<th><a href=\"test.php?l=$l&c=$newC&o=$o&sort=ac\">Ac</a></th>'; echo '</tr>'; echo ' <tr>'; echo ' <td><a href=\"magelo.php?char=$name\">$name</a></td>'; echo ' <td>$hp</td>'; echo ' <td>$mana</td>'; echo ' <td>$ac</td>'; echo ' </tr>'; echo '</table>'; } if($l != '0') $sql = "SELECT COUNT(*) FROM character_ WHERE character_.class = '$l';"; else $sql = "SELECT COUNT(*) FROM character_;"; $results = mysql_query("$sql"); $row = mysql_fetch_array($results); $count = $row['COUNT(*)']; $newC = max(0, $c - $numToDisplay); echo "<br><br><a href=\"test.php?l=$l&c=$newC&o=$o&sort=$sort\">Prev</a> "; $newC = min($c + $numToDisplay, max($count - $numToDisplay, 0)); echo "<a href=\"test.php?l=$l&c=$newC&o=$o&sort=$sort\">Next</a>"; this is houw i would code it if i was useing the table directly.. where it says //build temp table i would build the temp table here then read the info.. what i need is to take the info read pout it into an array then list it out in the table and still be able to hit next last links and go to the next/last 20.. but then i also need to be able to sort them by the diff types.. (the <th> is where they click to sort by that type> please help out anyway you can... Link to comment https://forums.phpfreaks.com/topic/115890-arrays-and-sorting/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.