seany123 Posted September 9, 2008 Share Posted September 9, 2008 i need some help with this game im making... Basically ive made 10 different cities, london, newyork etc.. ive gone onto my database and added $city to $players... how can i make it so when i enter a page, it will check what city the player is in, then show that cities contents. have i gone about this the right way? or would i need a whole new $City table? Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/ Share on other sites More sharing options...
DarkWater Posted September 9, 2008 Share Posted September 9, 2008 Why don't you post the current database schema? And yes, I'd suggest a cities table. Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/#findComment-637177 Share on other sites More sharing options...
seany123 Posted September 9, 2008 Author Share Posted September 9, 2008 just for another example, i want my players to have to be in same city to attack eachother... okay so im going to make a city table instead, so i made a quick city table with 4 cities in it, london, newyork, paris, washington. wow this is mind blowing, (i cant think). Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/#findComment-637180 Share on other sites More sharing options...
tbare Posted September 9, 2008 Share Posted September 9, 2008 what I would do is in the cities table, have the columns (ID,City,ETC) and in the players table, have a column for CityID that holds the ID column from the Cities table. Then do a query that gets all players where CityID = ?, and allow them attack each other... Just a thought... Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/#findComment-637194 Share on other sites More sharing options...
seany123 Posted September 9, 2008 Author Share Posted September 9, 2008 hmm so ill do a city table with, id and name. and ill add "cityid" in players table. Can anyone help me with a query which would diplay different cities according to what city id their in. Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/#findComment-637641 Share on other sites More sharing options...
Maq Posted September 9, 2008 Share Posted September 9, 2008 Can anyone help me with a query which would diplay different cities according to what city id their in. Did you mean different players according to what city they're in? Because seems to me you can only be in 1 city at a time... If this is the case then you should get the ID of both players and check to see if they're in the same city... $results = mysql_query("SELECT city_id FROM player_table WHERE player_id = ".$player1.""); $data = mysql_fetch_array($results) $player1_city_id = $data['city_id']; $results = mysql_query("SELECT city_id FROM player_table WHERE player_id = ".$player2.""); $data = mysql_fetch_array($results) $player2_city_id = $data['city_id']; if($player1_city_id == $player2_city_id) { echo 'fight!'; } else { echo 'throw error'; } ?> This probably isn't the best way to do it but you get the idea. Hope this helps! Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/#findComment-637676 Share on other sites More sharing options...
seany123 Posted September 9, 2008 Author Share Posted September 9, 2008 yes i get the idea... because i have like 10 different cities... is it possible to for when they go onto a certain it shows the correct .php page according to what city they are in? also in the city table, is id and city columns both needed? Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/#findComment-637695 Share on other sites More sharing options...
Maq Posted September 9, 2008 Share Posted September 9, 2008 also in the city table, is id and city columns both needed? Yes, you should have a primary key for the cities (id), and a column for the city name in the city table. Your tables should look something like this: Players Table id name city_id 1 tim 7 2 jim 3 3 bob 10 City Table id name 1 Philadelphia 2 Chicago 3 New York So now when you look up players you can reference their city_id and find it on the City Table. because i have like 10 different cities... is it possible to for when they go onto a certain it shows the correct .php page according to what city they are in? Yes. It depends how you want to do this but I recommend just passing a variable with the $_GET[''] method. For example, you could pass the city_id through via the URL with $_GET. Wherever you call this page use: $cityID = 1; Click here for the next page... That way when you get to the "page_name.php" you can retain the variable $cityID by simply doing: echo 'City ID: ' . $_GET['cityID']; That will display, "City ID: 1". I probably went off on a tangent, hope this answers your questions though. Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/#findComment-637721 Share on other sites More sharing options...
seany123 Posted September 9, 2008 Author Share Posted September 9, 2008 Yes. It depends how you want to do this but I recommend just passing a variable with the $_GET[''] method. For example, you could pass the city_id through via the URL with $_GET. Wherever you call this page use: $cityID = 1; <a href="page_name.php?cityid=".$cityID.">Click here for the next page...</a> That way when you get to the "page_name.php" you can retain the variable $cityID by simply doing: echo 'City ID: ' . $_GET['cityID']; That will display, "City ID: 1". I probably went off on a tangent, hope this answers your questions though. what im wanting is on a tool bar: one of the links saying name of city the player is currently in. the link then taking you to the city the players in. so instead of having another link to page, it goes straight to the certain city.php Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/#findComment-637845 Share on other sites More sharing options...
seany123 Posted September 9, 2008 Author Share Posted September 9, 2008 is anyone about to tell me how this could be done? Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/#findComment-637945 Share on other sites More sharing options...
seany123 Posted September 11, 2008 Author Share Posted September 11, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/123365-need-help-with-using-database/#findComment-638979 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.