I have this code on my game script (php). This checks if the player has a vehicle equipped, and that it still exists. My code:
if ($rs[vehicle] != 0) {
$sql_result2 = mysql_query("SELECT * FROM vehicles WHERE id='$rs[vehicle]'", $db);
if (mysql_num_rows($sql_result2) == 0) { mysql_query("UPDATE mobsters SET vehicle = 0 WHERE id ='$id'"); }
}
I want to edit this code so that if it does exist, it will also check the db_vehicles
table and find out details of the said vehicle (name, speed etc). A sloppy way of doing that is:
if ($rs[vehicle] != 0) {
$sql_result2 = mysql_query("SELECT * FROM vehicles WHERE id='$rs[vehicle]'", $db);
if (mysql_num_rows($sql_result2) == 0) {
mysql_query("UPDATE mobsters SET vehicle = 0 WHERE id ='$id'");
} else {
$ = mysql_fetch_array($sql_result2);
$sql_result3 = mysql_query("SELECT * FROM db_vehicles WHERE id='$[type]'", $db);
$ = mysql_fetch_array($sql_result3);
$name = $[name]; $speed = $[speed];
}
}
Obviously I'd like to do this with a JOIN to use as few queries as possible. What kind of join should I use?