basically two table work i want to select one head value against its id collect all data from second table and than second head value against its id collect all data and ...... my problem is when collect value from head table and against its id collect all values from second table but head value repeated again and again against second table values in while loop
<?php
$result = mysql_query("SELECT *
FROM account_head
LEFT JOIN account_head_name
ON account_head.ID = account_head_name.account_head_ID ");
while($array=mysql_fetch_array($result))
{
if($array > 0)
{
?>
<b><?php echo $array['Name'] ; ?> </b>
<br>
<?php echo $array['name'] ; ?>
<br>
<?php
}
}
In one - many relation the best way to get data is make two queries
$result = mysql_query("SELECT *
FROM account_head");
while($array=mysql_fetch_array($result))
{
?>
<b>Head Name:<?php echo $array['Name'] ; ?> </b>
<?php
$result1 = mysql_query("SELECT *
FROM account_head_name where account_head_ID = $array['ID'] ");
while($array1=mysql_fetch_array($result1))
?>
<br>
<?php echo $array1['name'] ; ?>
<br>
<?php
}
}
Note: Better to avoid mysql function Use mysqli instead.
Probably you have to write:
if(count($array) > 0)