The Arcive of vBulletin Modifications Site. |
|
|
#1
|
||||
|
||||
|
Okay, so I'm a pretty experienced MySQL programmer, but this problem has stumped me.
I'm getting some funky results when working with a nested MySQL query. It goes something like this: Code:
$cars = $DB_site->query("SELECT * FROM cars");
while ($car = $DB_site->fetch_array($cars)) {
$passengers= $DB_site->query("SELECT * FROM passengers WHERE car.id = '$car[id]'");
while ($passenger= $DB_site->fetch_array($passengers)) {
// Do stuff with data
// Display the data
}
}
Has anyone encountered a similar problem to this, and does anyone have a solution? |
|
#2
|
||||
|
||||
|
Problem solved. I discoverred the wonder that is "unset()".
|
|
#3
|
||||
|
||||
|
Ack! Avoid nested queries when possible. Use a JOIN query instead. You'll save processing time and system resources.
something like this: SELECT cars.id as cid, cars.field2 as cfield2, passengers.id as pid, passengers.field2 as pfield2 FROM cars c LEFT JOIN passengers p ON cars.id=passwngers.car_id ORDER BY cars.field3 ASC, passengers.field3 ASC |
![]() |
|
|
| X vBulletin 3.8.12 by vBS Debug Information | |
|---|---|
|
|
More Information |
|
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|