Jump to content

Archived

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

xtiancjs

sort order by variable?

Recommended Posts

Hi all,

Am wondering how to sort my results on a page by a variable. My sql code now is this:


mysql_select_db($database_broker, $broker);
$query_brokers = "SELECT * FROM brokers";
$query_limit_brokers = sprintf("%s LIMIT %d, %d", $query_brokers, $startRow_brokers, $maxRows_brokers);
$brokers = mysql_query($query_limit_brokers, $broker) or die(mysql_error());
$row_brokers = mysql_fetch_assoc($brokers);


The variable I have written looks like this :


$valrate1 = (($row_brokers['broker_rating']/$row_brokers['broker_num_votes'])+
($row_brokers['broker_rating_two']/$row_brokers['broker_num_votes_two'])+
($row_brokers['broker_rating_three']/$row_brokers['broker_num_votes_three']))/3;


basically, i want to add an ORDER BY $valrate1 to the sql query, have tried a few different things with no luck. Am not sure where the variable code should go , any ideas would be great.
xtian

Share this post


Link to post
Share on other sites
Hi This is what I had:


mysql_select_db($database_broker, $broker);
$query_brokers = "SELECT * FROM brokers ORDER BY '$valrate1' DESC";
$query_limit_brokers = sprintf("%s LIMIT %d, %d", $query_brokers, $startRow_brokers, $maxRows_brokers);
$brokers = mysql_query($query_limit_brokers, $broker) or die(mysql_error());
$row_brokers = mysql_fetch_assoc($brokers);
$valrate1 = (($row_brokers['broker_rating']/$row_brokers['broker_num_votes'])+
($row_brokers['broker_rating_two']/$row_brokers['broker_num_votes_two'])+ ($row_brokers['broker_rating_three']/$row_brokers['broker_num_votes_three']))/3;

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.