Jump to content

Archived

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

CanMan2004

two tables

Recommended Posts

Hi

I have a very complex query which currently looks in a table called 'users' and I want to be able to query a 2nd table (which is called "people") in the same statement, the 'people' table has the same fields as the 'users' table is currently searches.

How can I change the query to look in a 2nd table? My query is

[code]$sql = "SELECT * FROM users";

if ($_GET['name'] != "")
{
$sql =$searchsql." WHERE show = '1'";
}

$sql =$searchsql." LIMIT $from, $mr";[/code]

Any help would be great.

Thanks in advance

Dave

Share this post


Link to post
Share on other sites
[code]$sql = "SELECT u.*, p.* FROM users AS u, people AS p";

if($_GET['name'] != "")
{
$sql .= "WHERE u.show = '1' OR p.show = '1'";
}

$sql .= " LIMIT $from, $mr";[/code]

When looking at the results, remember that columns from users will be prefixed with a "u." and columns from people will be prefixed with a "p.".

Share this post


Link to post
Share on other sites

×

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.