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 Quote 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 Quote 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; Quote Link to comment https://forums.phpfreaks.com/topic/8418-sort-order-by-variable/#findComment-30803 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.