Query two tables on same page depending on ID

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

yinka
Forum Newbie
Posts: 12
Joined: Mon Aug 18, 2003 10:15 am

Post by yinka »

I get this error now.

Unknown column 'product_id' in 'where clause'

I was using that line of code because my main table is called "products."
That is where I am holding the the inormation for each product and setting the ID. Each table that I have in the array, I want to show up when the products table row comes up.

For example, I have product named "as." It is in the "products" table and it's ID is 1. When I go to that URL, I also want the table called "as" that holds all the information for that product. Does that make sense?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

have you actually got a column called product_id, according to that error message you haven't, and by looking at the other SQL statement you have constructed, the column you should be refering to is ID

change this line

Code: Select all

$query = "SELECT * FROM " . $product_array[$product_id] . " WHERE product_id = '$product_id'";
to

Code: Select all

$query = "SELECT * FROM " . $product_array[$product_id] . " WHERE id = '$product_id'";
The reason i ask about the line of code is becuase you set $query to equal the first SQL statement, then immeadiately overwrite it with another SQL statement!

Mark
yinka
Forum Newbie
Posts: 12
Joined: Mon Aug 18, 2003 10:15 am

Post by yinka »

ARGG! I don't know what the heck I am doing! The comumn that I have in the "products" table is just ID.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

well, the code i just gave you should have sorted out the last error then. Are you still getting errors?

Mark
yinka
Forum Newbie
Posts: 12
Joined: Mon Aug 18, 2003 10:15 am

Post by yinka »

I get this now:

Unknown column 'id' in 'where clause'

But now, I don't see in the code how I would get an ID from the "products table first.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

have a look at this mysql join tutorial.
yinka
Forum Newbie
Posts: 12
Joined: Mon Aug 18, 2003 10:15 am

Post by yinka »

Yeah, I guess what I have to do it join the tables. I'll try to figure out how to do it. Thanks guys.
Post Reply