Jump to content

Multiple tables


TEENFRONT

Recommended Posts

Hey Hey

I have a database with 3 tables. Tables are, users1, users2, and users3. to make things simple lets say they all have 1 column "username".

I wanna do this
$username = "Adam";
$sql ="SELECT username FROM user1, user2, user3 WHERE username = '$username'";


But the username, Adam, is only in 1 of the 3 tables. So the above doesnt work, it just fails to find Adam. Yet if i just do it with 1 table like this..

$username = "Adam";
$sql ="SELECT username FROM user1 WHERE username = '$username'";

it will find Adam if Adam is in users1.

I need to be able to locate Adam from all 3 tables. How do i do this?
Link to comment
https://forums.phpfreaks.com/topic/22949-multiple-tables/
Share on other sites

well i thought it was this.....

$username = "Adam";

$sql = "SELECT user1.username AS user1, user2.username AS user2, user3.username AS user3 FROM user1, user2, user3 WHERE user1.username = '$username' OR user2.username = '$username' OR user3.username = '$username';";
$results = mysql_query($sql) or die(mysql_error());

while($array = mysql_fetch_array($results))
{

echo $array['user1'];

echo"<br><br>";

echo $array['user2'];

echo"<br><br>";

echo $array['user3']; 
}

but it only works if Adam is in all 3 tables.... so maybe someone could help
Link to comment
https://forums.phpfreaks.com/topic/22949-multiple-tables/#findComment-103642
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.