I want to display the number of car makes for a particular car type in while loop.
I want something to look like this:
**Car Type 1**
Car name 1
Car name 2
**Car Type 2**
Car name 1
Car name 2
Car name 3
My problem is that,the data displayed for the car make is correct, But it repeats as many times the first while loop.
Like this:
**Car Type 1**
Car name 1
Car name 1
Car name 2
Car name 2
**Car Type 2**
Car name 1
Car name 1
Car name 1
Car name 2
Car name 2
Car name 2
Car name 3
Car name 3
Car name 3
I know it's because i placed the second while loop inside the first one.
How do i loop the car makes for the particular car type if i placed it outside the first while loop ?
My code is :
<?php
if (isset($num) && ($num > 0)) {
while ($row = mysql_fetch_array($result)) //first while loop
{
$carType_id = $row['carType_id'];
$carType = $row['carType'];
echo '<b>' . $carType . '</b><br/>';
mysql_select_db($database);
$query_name = "SELECT car_make.carMake_id,car_make.carMake,type_make.carMake_id,type_make.carType_id,car_type.carType_id FROM car_make,car_type,type_make WHERE car_make.carMake_id=type_make.carMake_id AND type_make.carType_id='$carType_id'";
$result_name = mysql_query($query_name) or die(mysql_error());
while ($row = mysql_fetch_array($result_name)) //second while loop
{
$carMake_id = $row['carMake_id'];
$carMake = $row['carMake'];
echo $carMake . '<BR/>';
}
}
}
?>
What is the mistake i did, and How can i fix this ?
group by Car_Namethat should solve the issue and you can avoid use of loop