JJohnsenDK Posted June 24, 2007 Share Posted June 24, 2007 Hey Im trying to sort this after the highest rated blog. I get the avg number from functions2.php with get_rating_avg() and then i want to sort the while loop after which user_blogs_id is highest. Here is the code: <?php require_once "maincore.php"; include('functions2.php'); $blogsQuery = mysql_query("SELECT * FROM user_blogs ORDER BY date DESC") or die(mysql_error()); while($blogsRow = mysql_fetch_array($blogsQuery)){ echo "<p>".get_rating_avg($blogsRow['user_blogs_id'], 1)."</p>"; //Bruger billede $image = get_useravatar($blogsRow['user_id']); if(empty($image)){ $image = "<img src='images/avatars/none.jpg' alt='".get_useravatar($blogsRow['user_id'])."' width='50' />"; }else{ $image = "<img src='images/avatars/".get_useravatar($blogsRow['user_id'])."' alt='".get_useravatar($blogsRow['user_id'])."' width='50' />"; } //Tekst echo " <table> <tr> <td style='width: 500px; border: 1px solid #000000;'> <table> <tr> <td> <table> <tr> <td><div class='user_blogs_image'>".$image."</div></td> </tr> </table> </td> <td> <table> <tr> <td><p>".$blogsRow['headline']."</p></td> </tr> <tr> <td><div><p>".get_username($blogsRow['user_id'])." | ".showdate("longdate",$blogsRow['date'])." | Kommentarer (".get_comments($blogsRow['user_blogs_id']).") | <a href='user_view_blog.php?blog=".$blogsRow['user_blogs_id']."'>Læs mere</a></p></div> <div><p>".substr($blogsRow['text'], 0, 100)."</p></div></td> </tr> </table> </td> </tr> </table> </td> <td> <table> <tr> <td> </td> </tr> </table> </td> </tr> </table> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56928-solved-sort-after-highest-avg-number-in-php/ Share on other sites More sharing options...
sasa Posted June 24, 2007 Share Posted June 24, 2007 try <?php require_once "maincore.php"; include('functions2.php'); $a = array(); $blogsQuery = mysql_query("SELECT * FROM user_blogs ORDER BY date DESC") or die(mysql_error()); while($blogsRow = mysql_fetch_array($blogsQuery)){ $av = get_rating_avg($blogsRow['user_blogs_id'], 1); $avg = "<p>".$av."</p>"; //Bruger billede $image = get_useravatar($blogsRow['user_id']); if(empty($image)){ $image = "<img src='images/avatars/none.jpg' alt='".get_useravatar($blogsRow['user_id'])."' width='50' />"; }else{ $image = "<img src='images/avatars/".get_useravatar($blogsRow['user_id'])."' alt='".get_useravatar($blogsRow['user_id'])."' width='50' />"; } //Tekst $text = " <table> <tr> <td style='width: 500px; border: 1px solid #000000;'> <table> <tr> <td> <table> <tr> <td><div class='user_blogs_image'>".$image."</div></td> </tr> </table> </td> <td> <table> <tr> <td><p>".$blogsRow['headline']."</p></td> </tr> <tr> <td><div><p>".get_username($blogsRow['user_id'])." | ".showdate("longdate",$blogsRow['date'])." | Kommentarer (".get_comments($blogsRow['user_blogs_id']).") | <a href='user_view_blog.php?blog=".$blogsRow['user_blogs_id']."'>Læs mere</a></p></div> <div><p>".substr($blogsRow['text'], 0, 100)."</p></div></td> </tr> </table> </td> </tr> </table> </td> <td> <table> <tr> <td> </td> </tr> </table> </td> </tr> </table> "; $a[] = array($av, $avg, $text); } array_multisort($a, SORT_DESC); foreach($a as $b){ echo $b[1],$b[2];} ?> not tested Quote Link to comment https://forums.phpfreaks.com/topic/56928-solved-sort-after-highest-avg-number-in-php/#findComment-281224 Share on other sites More sharing options...
JJohnsenDK Posted June 24, 2007 Author Share Posted June 24, 2007 it works ... thanks alot mate Quote Link to comment https://forums.phpfreaks.com/topic/56928-solved-sort-after-highest-avg-number-in-php/#findComment-281254 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.