Jump to content


Photo

How to order?


  • Please log in to reply
2 replies to this topic

#1 graphicguy

graphicguy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 19 August 2006 - 02:00 AM

Hey I want to order the results by $usertuts but im not to sure how to, here is the code can anyone help?


$get = mysql_query("SELECT * from users");
while ($users = mysql_fetch_array($get)){

$result21 = mysql_query("SELECT * FROM tutorials");
$tutorials = mysql_fetch_array($result21); 

$result1 = mysql_query("SELECT * FROM tutorials WHERE user = '$users[username]'");
$usertuts = mysql_num_rows($result1); 
$stuts = mysql_query("select views from tutorials WHERE user = '$users[username]' ");
$views = "0";
while($c = mysql_fetch_array($stuts))
{
$views = $views+$c[views];
}

echo"
<a href=\"index.php?act=users&user=$users[username]\"><b>$users[username]</b></a> | <a href=\"$users[website]\">$users[website]</a> | <b>$usertuts</b> Resources | <b>$views</b> Total views<br/><br/>

";

thanks!

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 19 August 2006 - 02:13 AM

I think this will work...although my SQL might be off a bit:

$query = '
	SELECT COUNT(tutorials.tutorials) as usertuts, COUNT(tutorials.views) as viewcount, users.username, users.website
	FROM users 
		LEFT JOIN tutorials ON users.user = tutorials.user
	ORDER BY COUNT(tutorials.tutorials)
	GROUP BY user';

while ($users = mysql_fetch_array($query)){
	echo '
		<a href="index.php?act=users&user=' . $users['username'] . '"><b>' . $users['username'] . '</b></a> | 
		<a href="' . $users['website'] . '">' . $users['website'] . '</a> | 
		<b>' . $users['usertuts'] . '</b> Resources | 
		<b>' . $users['viewcount' ]. '</b> Total views<br/><br/>';
}


#3 graphicguy

graphicguy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 21 August 2006 - 12:37 AM

Actually that did not work :(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users