Jump to content

Recommended Posts

 

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
}
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/205606-mysql-help-assorting/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.