Jump to content

How to order?


graphicguy

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!
Link to comment
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]
Link to comment
Share on other sites

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.