xtiancjs Posted April 26, 2006 Share Posted April 26, 2006 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 https://forums.phpfreaks.com/topic/8418-sort-order-by-variable/ Share on other sites More sharing options...
kenrbnsn Posted April 26, 2006 Share Posted April 26, 2006 Show us what you've tried...Ken Link to comment https://forums.phpfreaks.com/topic/8418-sort-order-by-variable/#findComment-30800 Share on other sites More sharing options...
xtiancjs Posted April 26, 2006 Author Share Posted April 26, 2006 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 https://forums.phpfreaks.com/topic/8418-sort-order-by-variable/#findComment-30803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.