What I am hoping to do is filter one database query by another.
I have two databases and they both have a field call vehicle_type. What I want to happen is that vehicle_type from the products database filters what is shown from the accessories database.
These are my SQL queries
SELECT * FROM products WHERE id = %s",
SELECT * FROM accessories WHERE vehicle_type=''";
I think the accessories query should look like
SELECT * FROM accessories WHERE vehicle_type=''$vehicle_type";
but I don't know how to give $vehicle_type a value from the products database.
Hope this makes sense, any help would be greatly appreciated.
Thanks Dennis :0)
How to filter one database query by another
Moderator: General Moderators
-
dennis_doug
- Forum Newbie
- Posts: 5
- Joined: Fri Mar 04, 2005 10:56 pm
- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
Perhaps this will help. Fix the $product_id so it matches whatever variable you were going to send to the query.
Code: Select all
SELECT a.* FROM products p, accessories a WHERE (p.vehicle_type = a.vehicle_type) AND (p.id = $product_id)Just a different approach, using JOINS...
Code: Select all
select
accessories.*
from
accessories
inner join products on products.vehicle_type = accessories.vehicle_type
where
products.vehicle_type = '<whatever>'