Jump to content

Archived

This topic is now archived and is closed to further replies.

graphicguy

How to order?

Recommended Posts

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


[code]$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/>

";[/code]

thanks!

Share this post


Link to post
Share on other sites
I think this will work...although my SQL might be off a bit:

[code]$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/>';
}[/code]

Share this post


Link to post
Share on other sites

×

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.