Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/14599-two-tables/
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.".
Link to comment
https://forums.phpfreaks.com/topic/14599-two-tables/#findComment-58022
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.