thecase Posted August 13, 2008 Share Posted August 13, 2008 Hi, Im making a game. I have a the teams points as a variable $teampoints now this for example reads 5 I want to echo out just 2 teams, the one bellow 5 and the above 5 in a dropdown. If there is more than one team at 4 then let SQL/PHP pick any it doesnt really matter. If there is no lower just above or vice versa, then just take that 1 value. How can I do this Thanks Quote Link to comment https://forums.phpfreaks.com/topic/119560-solved-query-above-and-bellow-number/ Share on other sites More sharing options...
ignace Posted August 13, 2008 Share Posted August 13, 2008 select distinct points from teams where points between $teampoints - 1 and $teampoints + 1 Quote Link to comment https://forums.phpfreaks.com/topic/119560-solved-query-above-and-bellow-number/#findComment-615966 Share on other sites More sharing options...
thecase Posted August 13, 2008 Author Share Posted August 13, 2008 Doh good idea but was happends if its 5 so 5 - 1 = 4 and there are 5 teams = 4 points does sql/php pick a random team? Quote Link to comment https://forums.phpfreaks.com/topic/119560-solved-query-above-and-bellow-number/#findComment-616024 Share on other sites More sharing options...
fenway Posted August 14, 2008 Share Posted August 14, 2008 Doh good idea but was happends if its 5 so 5 - 1 = 4 and there are 5 teams = 4 points does sql/php pick a random team? Pseudo-random, yes. Quote Link to comment https://forums.phpfreaks.com/topic/119560-solved-query-above-and-bellow-number/#findComment-616095 Share on other sites More sharing options...
thecase Posted August 14, 2008 Author Share Posted August 14, 2008 Hmm I notice a problem this is the query I set up $currentpointsp = "$ladderd$p"; $fetchpoints = "SELECT * FROM aacl_team WHERE teamname='$teamnamme'" or trigger_error("Query: $fetchpoints\n<br />MySQL Error: ". mysql_error()); $fetchpoints2 = mysql_query ($fetchpoints); while ($fetchpoints3 = mysql_fetch_assoc($fetchpoints2)) { $currentpoints = $fetchpoints3["$currentpointsp"]; $lesscurrentpoints = $currentpoints - 1; $fetchmorepoints = "SELECT * FROM aacl_team WHERE $ladder='0' AND $currentpointsp=$lesscurrentpoints" or trigger_error("Query: $fetchmorepoints\n<br />MySQL Error: ". mysql_error()); $fetchmorepoints2 = mysql_query ($fetchmorepoints); while ($fetchmorepoints3 = mysql_fetch_assoc($fetchmorepoints2)) { $morepointteam = $fetchmorepoints3['teamname']; $morepointteamid = $fetchmorepoints3['id']; $morecurrentpoints = $currentpoints + 1; $fetchlesspoints = "SELECT * FROM aacl_team WHERE $ladder='0' AND $currentpointsp=$morecurrentpoints" or trigger_error("Query: $fetchlesspoints\n<br />MySQL Error: ". mysql_error()); $fetchlesspoints2 = mysql_query ($fetchlesspoints); while ($fetchlesspoints3 = mysql_fetch_assoc($fetchlesspoints2)) { $lesspointteam = $fetchlesspoints3['teamname']; $lesspointteamid = $fetchlesspoints3['id']; now if the team has 5 points team 2 have 4 it displays that but if the next highest team only has 10 it will not display it its looking for 6 ... how can I make it search for the next lowest from 5 and vice versa. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/119560-solved-query-above-and-bellow-number/#findComment-616740 Share on other sites More sharing options...
thecase Posted August 14, 2008 Author Share Posted August 14, 2008 Fixed just changed the = to > and < Quote Link to comment https://forums.phpfreaks.com/topic/119560-solved-query-above-and-bellow-number/#findComment-616835 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.