Stieny Posted December 24, 2009 Share Posted December 24, 2009 OK. Here is what I am trying to do. I have the conditions set, and if the conditions are met, I want to randomly find a user id, and username from a table, and then store each of these names in the table of the user that is searching. Essentially, a player will search for another player's "location" and be able to select it from a drop down list once it is found. I am fairly sure I can use serialize to store the data, however I am stumped as to how to retrieve the data to store. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/ Share on other sites More sharing options...
ram4nd Posted December 24, 2009 Share Posted December 24, 2009 Do you already have the table made? Or you want to also make the tables. Type to google "mysql php tutorial" and you get answers to your question. I also recommend to use a php freamwork. Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/#findComment-983751 Share on other sites More sharing options...
Stieny Posted December 24, 2009 Author Share Posted December 24, 2009 Yes, way past that. Here is what I have so far: $mod = rand (0,100); $chance = (($user[rangers]*$bonus[rangers]) + ($user[rangers]*$bonus[explore]))*$mod; if($user[turns] <= 0) { header('refresh: 4; url= exploration.php'); echo $error_header; echo "You do not have enough turns to do that."; echo $footer; exit(); } if($chance <= 0 and $chance < 199) { header('refresh: 4; url= exploration.php'); echo $error_header; echo "Your rangers have found nothing."; echo $footer; exit(); } if($chance > 200) { $qry="SELECT * FROM members"; $result = mysql_query($qry); while($row = mysql_fetch_array($result)) { $array=array($row[leader]); } $loc=array_rand($array,1); header('refresh: 4; url= exploration.php'); echo $success_header; echo "Your rangers have found $loc."; echo $footer; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/#findComment-983753 Share on other sites More sharing options...
Stieny Posted December 24, 2009 Author Share Posted December 24, 2009 I think my problem is with : $array=array($row[leader]); How do i set the fetched row as the array? Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/#findComment-983762 Share on other sites More sharing options...
ignace Posted December 24, 2009 Share Posted December 24, 2009 $array = $row Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/#findComment-983784 Share on other sites More sharing options...
ram4nd Posted December 24, 2009 Share Posted December 24, 2009 You don't set it it already is. So, like this $row is array: $row = mysql_fetch_array($result) Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/#findComment-983802 Share on other sites More sharing options...
Stieny Posted December 25, 2009 Author Share Posted December 25, 2009 ok, with this code: if($chance > 200) { $qry="SELECT leader FROM members"; $result = mysql_query($qry); $row = mysql_fetch_array($result); $loc=array_rand($row,1); header('refresh: 4; url= exploration.php'); echo $success_header; echo "Your rangers have found $loc."; echo $footer; exit(); } I get returns of zero or leader. I would like it to return the name of a leader. Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/#findComment-983872 Share on other sites More sharing options...
Stieny Posted December 25, 2009 Author Share Posted December 25, 2009 ok, tried this, but still didn't work.... if($chance > 200) { $qry="SELECT leader FROM members"; $result = mysql_query($qry); $row = mysql_fetch_array($result); $loc=array_rand($row,1); header('refresh: 4; url= exploration.php'); echo $success_header; echo "Your rangers have found "; echo $row[$loc[0]]; echo $footer; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/#findComment-983881 Share on other sites More sharing options...
Stieny Posted December 25, 2009 Author Share Posted December 25, 2009 ok, i have come to the conclusion that I need to populate an array with leader names from a while loop. How would I do that? Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/#findComment-983901 Share on other sites More sharing options...
Stieny Posted December 25, 2009 Author Share Posted December 25, 2009 OK to be a little clearer i need to make a resultset array, from a fetched row array. Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/#findComment-983904 Share on other sites More sharing options...
Stieny Posted December 26, 2009 Author Share Posted December 26, 2009 ok, so the i solved my problem.... to find a random leader, i used rand to generate a leader id... i hate it when i don't K.I.S.S................. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/186268-i-am-stumped/#findComment-984274 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.