Jump to content

help using two tables from database.


seany123

Recommended Posts

i have two tables which i need to pull values from ones called "players" and it has a all information about the user and (city_id) in it.

 

The other table is called "city" and it has (city_id and city_name) in it

 

what i want to do is when $players->city_id = 1.... for it to echo the name of the city using the (city) table.

 

the last catch is im trying to do a page which shows alot of different peoples "city_name" value...

 

heres the code i already have...

 

<?php
/Check for user ID
if (!$_GET['id'])
{
header("Location: members.php");
}
else
{
$query = $db->execute("select `id`, `username`, `city_id` from `players` where `username`=?", array($_GET['id']));
if ($query->recordcount() == 0)
{
	header("Location: members.php");
}
else
{
	$profile = $query->fetchrow();
}
}
?>

now if i set the below code to $player->city_id... then it displays MY city name...
but setting it to profile doesnt show anyones.
<?
$query = $db->execute("select * from `city` where `city_id` like '$profile->city_id'");
$city = $query->fetchrow();
?>

 

to echo my code:

<?=($city['city_name'])?>

 

 

can anyone give me a hand?

Link to comment
https://forums.phpfreaks.com/topic/152005-help-using-two-tables-from-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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