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
Comparing two variables in two different tables
Moderator: General Moderators
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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????
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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.
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.