Jump to content


Photo

two tables


  • Please log in to reply
1 reply to this topic

#1 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 14 July 2006 - 04:57 PM

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

$sql = "SELECT * FROM users";

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

$sql =$searchsql." LIMIT $from, $mr";

Any help would be great.

Thanks in advance

Dave

#2 Oldiesmann

Oldiesmann
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts
  • LocationCincinnati, Ohio

Posted 14 July 2006 - 05:18 PM

$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";

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.".
The Oldiesmann
SMF Project Manager
SMF+Gallery2 - Beta3.1 now available




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users