PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Now what i want to do is link "Player" and "Exp. Points" so when a user clicks on it, the data will sort itself by ascending / descending values. Could someone please give me an example?
anybody here can explain why we are using extract() here???
I have understood the basic concept of extract() to treat keys as variable names and values as variable values.
but why are we using it here
I used to use extract when I first started working with php especially when was returning a ton of results...probably just out of laziness (didn't want to write out the whole array every time I wanted to do something with values).
I always used the EXTR_OVERWRITE extract type and started running into issues with overwriting other vars so I started steering away from it. Now, out of habit, I just write out the whole array...but whatever works.
thanks, its almost exactley what i want. if i understand what is happening correctley, when you click on the link it passes asc / desc through the url and then in the sql query it takes $ordr and does what ever it is set to. My next question is how would i pass what it is to "ORDER BY" through the URL. When i was messing with the code you gave me i edited it so it looks like this now
<?php
include "config.php";
include "language.php";
$ordr = (isset($_GET['ordr']) ? $_GET['ordr'] : "asc");
$result = mysql_query("SELECT * FROM stats ORDER BY player $ordr", $db);
echo "<center>
<table width=\"75%\" border=\"1\">
<tr>
<td width=\"12%\"><div align=\"center\"><strong><a href=\"raw.php?ordr=".(isset($_GET['ordr']) && $_GET['ordr'] == "asc" ? "desc" : "asc")."\">player</a></strong></div></td>
<td width=\"12%\"><div align=\"center\"><strong><a href=\"raw.php?ordr=".(isset($_GET['ordr']) && $_GET['ordr'] == "asc" ? "desc" : "asc")."\">points</a></strong></div></td>
</tr>";
while ($row = mysql_fetch_assoc($result))
{
extract($row);
echo "<tr>
<td>$player</td>
<td>$team_experience_points</td>
</tr>";
}
echo "</table></center>";
?>
When i click on player it does what i want it to do. BUt when i click on points it still orders it by player because in the sql query it is set to player. My new question is how would i send player and points through the URL?
when i echo $fn and click points i get "team_experience_point"
theoretically it should be working..
i added another one to see if it was an error in my coding or something. it wasnt. except when i added the new one it didnt sort it by player...which leads me to belive it is sorting it properly.... however the data is incorrect....
here is Points Acending
120437
181255
456610
46389
and here is the new one Acending
1727
2422
3369
695
neither one is sorted properly according to their true value..however they are sorted properly according to the first 2 digits.... any ideas on that??