Jump to content

sort order by variable?


xtiancjs

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
Link to comment
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;
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.