graphicguy Posted August 19, 2006 Share Posted August 19, 2006 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 https://forums.phpfreaks.com/topic/18002-how-to-order/ Share on other sites More sharing options...
hitman6003 Posted August 19, 2006 Share Posted August 19, 2006 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 https://forums.phpfreaks.com/topic/18002-how-to-order/#findComment-77093 Share on other sites More sharing options...
graphicguy Posted August 21, 2006 Author Share Posted August 21, 2006 Actually that did not work :( Link to comment https://forums.phpfreaks.com/topic/18002-how-to-order/#findComment-77809 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.