Errant_Shadow Posted January 30, 2009 Share Posted January 30, 2009 I gave a game where players can win a prize if they have the best game of the day. So I am writing a script that will assign a winner for the previous day if one is not already assigned. The winner is the player who finished his round with the least number of guesses (clicks) in the least amount of time (play_time) So my first question is, can you order a query by 2 fields? (both clicks and play_time) My second question is, what is wrong with my script (below)? When I run it, it tells me "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /.../test.php on line 12" 10 $query = "SELECT 'game_id' FROM 'games' WHERE date='$yesterday' ORDER BY 'clicks' ASC"; 11 $result = mysql_query($query); 12 $winningGame = mysql_fetch_array($result, MYSQL_NUM); 13 echo 'Game ' . $winningGame[0] . ' selected...'; 14 $query = "UPDATE games SET win='1' WHERE game_id='$winningGame[0]'"; 15 $result = mysql_query($query); 16 if(mysql_affected_rows() > 0){ 17 echo 'Game ' . $result . ' updated...'; 18 } else { 19 echo 'error...'; 20 } Server version: 5.0.67-community Quote Link to comment https://forums.phpfreaks.com/topic/143099-solved-selecting-and-using-data-from-a-database/ Share on other sites More sharing options...
waterssaz Posted January 30, 2009 Share Posted January 30, 2009 Yes you can use ORDER BY for more than one column and the syntax for your query is incorrect. You do not need the single quotes around the SELECT column and FROM clause :-) Quote Link to comment https://forums.phpfreaks.com/topic/143099-solved-selecting-and-using-data-from-a-database/#findComment-750561 Share on other sites More sharing options...
Errant_Shadow Posted January 31, 2009 Author Share Posted January 31, 2009 Would the multiple order by just be commas? "ORDER BY 'clicks', 'play_time' ASC" or each individually? "ORDER BY 'clicks' ASC, ORDER BY 'play_time' ASC" or am I even close >>? Quote Link to comment https://forums.phpfreaks.com/topic/143099-solved-selecting-and-using-data-from-a-database/#findComment-751041 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.