Deanznet Posted June 23, 2010 Share Posted June 23, 2010 This shows the Username and the Money they have in the account. Now heres my question.. How can i assort the Value row so i can have it in from highest to lowest? I tried order By but it did not work.. The data is in 2 different tables using a Join i think . HELPS! <? include ("../conf/conn.php"); ?> <? function current_balance($userid) { $query = "SELECT SUM(value) FROM user_banking WHERE userid='".$userid."'"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)) { if($row['SUM(value)'] == 0) { return 0; } else { return $row['SUM(value)']; } } } ?> <?php $sql = mysql_query("SELECT * FROM users") or die(mysql_error()); while($data = mysql_fetch_array($sql)) { if(current_balance($data['id']) > 0) { ?> <table> <tr> <td><?php echo $data['login']; ?></td> <td><?php echo current_balance($data['id']); ?></td> </tr> <?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/205606-mysql-help-assorting/ Share on other sites More sharing options...
sKunKbad Posted June 23, 2010 Share Posted June 23, 2010 You might take a look at this: http://www.webmasterworld.com/forum88/3146.htm and a lot of other searches on Google Quote Link to comment https://forums.phpfreaks.com/topic/205606-mysql-help-assorting/#findComment-1075911 Share on other sites More sharing options...
TapeGun007 Posted June 23, 2010 Share Posted June 23, 2010 Have you tried posted in the MySQL help section of this website? Perhaps creating a query that sorts and pulling the data from that would be easier than trying to pull unsorted data and using php to sort it. OR Maybe you can store the users into an array with a key, then store the money into an array with the same keys. Then sort the money array and match the keys in the user array? I don't know if this is accurate, only one of these guru guys can answer that. Php doesn't exactly do multidimensional array sort as I found out the hard way. Quote Link to comment https://forums.phpfreaks.com/topic/205606-mysql-help-assorting/#findComment-1075986 Share on other sites More sharing options...
bluejay002 Posted June 23, 2010 Share Posted June 23, 2010 I prefer doing this in SQL. Post up your table design, what you want to fetch and the rules how your tables are related. Then guys will help you out in MySQL forums. Well, that would also mean transferring this thread to that one. Quote Link to comment https://forums.phpfreaks.com/topic/205606-mysql-help-assorting/#findComment-1075990 Share on other sites More sharing options...
TapeGun007 Posted June 23, 2010 Share Posted June 23, 2010 I prefer doing this in SQL. Post up your table design, what you want to fetch and the rules how your tables are related. Then guys will help you out in MySQL forums. Well, that would also mean transferring this thread to that one. I couldn't agree more, if it was my problem, I'd be working on the SQL side of things. Quote Link to comment https://forums.phpfreaks.com/topic/205606-mysql-help-assorting/#findComment-1075992 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.