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