Hi, I'm trying to select from 3 tables but I can't seem to get it right. Here is the code:

$query_Recordset1 = sprintf("SELECT * , image.user_id, image.name, page.user_id, page.urlcode FROM users JOIN mystuff.page JOIN mystuff.image ON page.user_id = image.user_id = users.user_id WHERE users.last_name = %s AND users.first_name = %s", GetSQLValueString($colname_Recordset1, "text"),GetSQLValueString($colname2_Recordset1, "text"),GetSQLValueString($colname3_Recordset1, "text"));

If I remove the page table it works perfect but when I add it in I have problems. Any thoughts?
Thanks!

I got it to work but still open to any suggestions.
Here is what I changed:

("SELECT * , image.user_id, image.name, page.user_id, page.urlcode FROM users JOIN mystuff.page JOIN mystuff.image ON image.user_id = users.user_id WHERE page.user_id = users.user_id AND users.last_name = %s AND users.first_name = %s"

You also try this

("SELECT * , image.user_id, image.name, page.user_id, page.urlcode FROM users JOIN mystuff.page ON (user.user_id=page.user_id) JOIN mystuff.image ON image.user_id = users.user_id WHERE page.user_id = users.user_id AND users.last_name = %s AND users.first_name = %s"

Hi, I'm trying to select from 3 tables but I can't seem to get it right. Here is the code:

$query_Recordset1 = sprintf("SELECT * , image.user_id, image.name, page.user_id, page.urlcode FROM users JOIN mystuff.page JOIN mystuff.image ON page.user_id = image.user_id = users.user_id WHERE users.last_name = %s AND users.first_name = %s", GetSQLValueString($colname_Recordset1, "text"),GetSQLValueString($colname2_Recordset1, "text"),GetSQLValueString($colname3_Recordset1, "text"));

If I remove the page table it works perfect but when I add it in I have problems. Any thoughts?
Thanks!

Try this one out
Table: image | page | mystuff | users
Fields: image = user_id | image.name |
page = user_id | urlcode
mystuff = image
users = user_id | last_name | first_name

$lastname = $_GET[lastname]; //use is GET form
$firstname = $_GET[firstname]; //use is GET form

$sql = "SELECT * FROM users a, page b, image c, mystuff d WHERE a.user_id=b.user_id ";
$sql .= "AND a.user_id=c.user_id ";
$sql .= "AND b.user_id=c.user_id ";
$sql .= "AND a.last_name LIKE '%$lastname' ";
$sql .= "AND a.first_name LIKE '%$firstname' ";

$result = mysql_query($sql);
/*
display here the mysql_fetch_array and echo the result.
*/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.