Jump to content

need help with using database..


seany123

Recommended Posts

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?

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.