Comparing two variables in two different tables

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

Post Reply
mkkay
Forum Newbie
Posts: 16
Joined: Mon Oct 22, 2007 5:42 pm

Comparing two variables in two different tables

Post by mkkay »

I am trying to compare two variables that are in different tables in a search.....

here is the code that is only comaring one at a time

if(!empty($_GET[search_make]))
{
$query[] = "cars_vehicle.VehicleName = '$_GET[search_make]' ";
}
in this code i want to make it compare the search to aother variable in a table and if it matches that variable then it returns the cars_vehicle.VehicleName
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What's the question?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I'm also confused... do you want a SELECT....WHERE.... clause?
mkkay
Forum Newbie
Posts: 16
Joined: Mon Oct 22, 2007 5:42 pm

Post by mkkay »

Sorry..my question is how do i add the extra bit so that it can compare the two and return the correct details.... i.e how do i add this code to the get string cars_listings.VehicleMake = cars_vehicle.VehicleID"; without getting an error?
mkkay
Forum Newbie
Posts: 16
Joined: Mon Oct 22, 2007 5:42 pm

Post by mkkay »

Okay to explain i have two tables cars_vehicles that holds the list of vehicle names and the ID of each vehicle name and in another i have car_listings that holds the data of the listed vehicles and the vehicle make is saved as an ID and it is compard to the VEhicle ID in the car_vehicles table to get which car it is, i.e toyota, subaru etc. However i want to add a drop down button on the search that lists the cars that are already listed. i have got this working i.e when yo uclick the arrow it shows the models of the listed cars but i want the user to be able to search for all types of a certain car, the code i posted above should do this but when i add the code it says the table cars_vehicle does not exist and when i change it to cars_listings.VehicleMake it just returns no results yet the cars are there????
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

i think you want to SELECT details of a vehicle WHERE a column of that vehicle matches a column in another table.

http://dev.mysql.com/doc/refman/5.0/en/select.html

Also, you should definitely be using MySQL_real_escape_string() on the $_GET variable before using it in the query. Major security issue.
Post Reply