Jump to content

[SOLVED] Why wont this order?


iceblox

Recommended Posts

Hi Guys,

 

Thanks all for your help. I think i was trying to over complicate something that should have been so easy!

 

Im pretty much there but i need to chuck in a join as well, so far the query is this;

 

<?php

$result = $db->sql_query("SELECT rating_id, avg(rating_num) AS columnaverage FROM ratings GROUP BY rating_id ORDER BY columnaverage DESC");
                			while($row = $db->sql_fetchrow($result))
		{
                $format_number = number_format($row[columnaverage], 2, '.', '');
                echo "<br>$row[rating_id] <b>$format_number</b>";
}
?>

 

Normally i would join a table like this

 

$query = "SELECT * FROM ratings a, models b WHERE a.rating_id = b.modid GROUP BY rating_id";

 

but as i normally select * im not sure how i would go about this when im selecting certain data?

 

Is any one able to help me to get this done?

 

Thanks, Phil

Link to comment
Share on other sites

Hi Keith,

 

Sorry i didnt give much detail! I needed to join my models table.

 

But i tried this;

 

<?php


   
        $result2 = $db->sql_query("SELECT rating_id, modname, manname, modid, avg(rating_num) AS columnaverage FROM ratings a, models b WHERE a.rating_id = b.modid GROUP BY rating_id ORDER BY columnaverage DESC");
                			while($row2 = $db->sql_fetchrow($result2))
		{
                $format_number = number_format($row2[columnaverage], 2, '.', '');
                echo "<br><a target=\"_blank\" href=\"$row2[manname]-$row2[modname]-Mobile-Review-$row2[modid].html\">$row2[manname] $row2[modname]</a> <b>$format_number</b>";


}
?>

 

And got it to work!!

 

Thanks for all your help again!

 

Thanks, Phil

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.