基本上两个表工作我想选择一个头值来对付它的id从第二个表中收集所有数据而不是第二个头值对它的id收集所有数据......我的问题是从头表中收集值时并且它的id收集来自第二个表的所有值,但是头部值一次又一次地重复对着while循环中的第二个表值
<?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
}
}
答案 0 :(得分:0)
可能你必须写:
if(count($array) > 0)
答案 1 :(得分:0)
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
}
}