Page 1 of 1
Comparing two variables in two different tables
Posted: Sat Nov 03, 2007 12:16 pm
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
Posted: Sat Nov 03, 2007 12:19 pm
by feyd
What's the question?
Posted: Sat Nov 03, 2007 12:53 pm
by Kieran Huggins
I'm also confused... do you want a SELECT....WHERE.... clause?
Posted: Sat Nov 03, 2007 12:54 pm
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?
Posted: Sat Nov 03, 2007 1:01 pm
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????
Posted: Sat Nov 03, 2007 1:04 pm
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.