I need a query that loops data from two tables. The two tables I have are VEHICLES and VEHICLES_DB.
The VEHICLES_DB table is a list of all the different types of vehicles in the database, including their speeds, picture, name, etc.
The VEHICLES table is a list of all vehicles, and which member it belongs too. It just contains the columns id, type, and member. The type column relates to which vehicle it is from VEHICLES_DB.
I have a page that shows you all the vehicles you own, grouped by each type. Then for each grouped type, it would have to refer to the VEHICLES_DB table to get that vehicles info. Something like:
$sql_result = mysql_query("SELECT * FROM vehicles WHERE member='$your_id' GROUP BY type", $db);
while ($rs = mysql_fetch_array($sql_result)) {
$sql_result2 = mysql_query("SELECT * FROM vehicles_db WHERE type='$rs[type]'", $db);
$rs2 = mysql_fetch_array($sql_result2);
// display vehicle
}
This method seems sloppy, for each vehicle type you own its querying the vehicles_db database, is there a better way to do it?
PS: Im not very good or knowledgeable with JOINs yet.