Dethman Posted January 27, 2009 Share Posted January 27, 2009 Ok guys a brief overview, I have listed where I need to something and what inside the comments hope it helps This is making me dizzy .lol. Here just look at what I am trying to do: <?php # # Basically I need to make this function in order to randomly place the user on the map # function setPlayerOnMap(){ $q=mysql_query("SELECT * FROM `SystemInfo` WHERE `id` = '1'") or die("Unable to connect"); $row=mysql_fetch_array($q); $set_land=$row['land']; $set_area=$row['area']; $set_line=$row['line']; while(mysql_num_rows(mysql_query("SELECT `villageID` FROM `map` WHERE `land` = '$set_land' AND `line` = '$set_line' AND `area` = '$set_area'")) > 0){ /* Basically I need to randomize $set_land, $set_area and $set_line untill we come to a villageID that is not greater than zero the max info is below thanx for all your help. $set_land max is 7 $set_area max is 60 $set_line max is 6 so we have : $set_land places are 1-7 $set_area places are 1-60 $set_line places are 1-6 Again I must randomize each var and check each time it is randomized to see if it the current randomizes are making the villageID in the table map is not greater than zero if it is not keep randomizing until it is. Thanx for any Help, Brian Flores CEO Nimbus Games,llc */ } ?> Thanx for any Help, Brian Flores CEO Nimbus Games,llc Link to comment https://forums.phpfreaks.com/topic/142570-randomizing-over-and-over-untill-it-is-clear-with-the-sql-query/ Share on other sites More sharing options...
cooldude832 Posted January 27, 2009 Share Posted January 27, 2009 I think your logic is backwards You want to get the location of the villages and then from the array of those generate random start spots. If I am following what you are doing right Link to comment https://forums.phpfreaks.com/topic/142570-randomizing-over-and-over-untill-it-is-clear-with-the-sql-query/#findComment-747147 Share on other sites More sharing options...
Dethman Posted January 27, 2009 Author Share Posted January 27, 2009 Hmm that would work, How exactly would I do that sorry really tired, And I am not that familliar with arrays any help? Link to comment https://forums.phpfreaks.com/topic/142570-randomizing-over-and-over-untill-it-is-clear-with-the-sql-query/#findComment-747149 Share on other sites More sharing options...
cooldude832 Posted January 27, 2009 Share Posted January 27, 2009 Write a query to get the X,Y,Z Cords (What ever you call them area/line etc.) of each Village and we'll work from there Link to comment https://forums.phpfreaks.com/topic/142570-randomizing-over-and-over-untill-it-is-clear-with-the-sql-query/#findComment-747150 Share on other sites More sharing options...
Dethman Posted January 27, 2009 Author Share Posted January 27, 2009 Ok Here you go <?php $query=("SELECT `land`, `line`, `area` FROM `map` WHERE `villageID` = '0'"); $res=mysql_query($query) OR DIE("UNABLE TO CONNECT, ERROR:<BR /><BR /><BR />".mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/142570-randomizing-over-and-over-untill-it-is-clear-with-the-sql-query/#findComment-747153 Share on other sites More sharing options...
cooldude832 Posted January 27, 2009 Share Posted January 27, 2009 That is trivial you should only get 1 Location don't u want to randomize it to a random location? <?php $query=("SELECT `land`, `line`, `area`, `villageID` FROM `map` WHERE `villageID` = '0'"); $res=mysql_query($query) OR DIE("UNABLE TO CONNECT, ERROR:<BR /><BR /><BR />".mysql_error()); $landmarks = array(); while($row = mysql_fetch_assoc($r)){ foreach($row as $key=>$value){ $landmarks[$row['villageID']][$key] = $value; } } ?> Then select a random item from the array $landmarks (array_rand) and then your are all set ?> [/code] Link to comment https://forums.phpfreaks.com/topic/142570-randomizing-over-and-over-untill-it-is-clear-with-the-sql-query/#findComment-747155 Share on other sites More sharing options...
Dethman Posted January 27, 2009 Author Share Posted January 27, 2009 Ok kinda confused :S sorry, So how would I select the proper `land` `line` and `area` from the array? Example would be nice as I have not dabbled with arrays? Thanx Link to comment https://forums.phpfreaks.com/topic/142570-randomizing-over-and-over-untill-it-is-clear-with-the-sql-query/#findComment-747159 Share on other sites More sharing options...
redarrow Posted January 27, 2009 Share Posted January 27, 2009 show us as a array example code, how this works you have all confused me badly. Link to comment https://forums.phpfreaks.com/topic/142570-randomizing-over-and-over-untill-it-is-clear-with-the-sql-query/#findComment-747167 Share on other sites More sharing options...
Dethman Posted January 27, 2009 Author Share Posted January 27, 2009 Bump Link to comment https://forums.phpfreaks.com/topic/142570-randomizing-over-and-over-untill-it-is-clear-with-the-sql-query/#findComment-747829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.