0
我有一个示例数据库:错误组由php在mysql中的id?
brand(id, name)
(1, 'Apple')
(2, 'Dell')
model(id, name, brand_id)
(1, 'Macbook', 1)
(2, 'Iphone', 1)
(3, 'Vostro', 2)
和PHP MySQL代码:
<?php
// Make a MySQL Connection
$query = "SELECT * FROM model";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
$brand_id = array();
$brand_id = array_unique($row['brand_id']);
?>
<table>
<?php for($i=0; $i<count(brand_id); $i++) {?>
<tr>
<td><?php echo $row['name'] ?></td>
<tr/>
<?php }?>
</table>
,并导致收益2 TR的2 brand_id,但显示结果的所有型号名称
<table>
<tr><td>Macbook, Iphone, Vostro</td></tr>
<tr><td>Macbook, Iphone, Vostro</td></tr>
</table>
如何解决它的结果是:
<table>
<tr><td>Macbook, Iphone</td></tr>
<tr><td>Vostro</td></tr>
</table>
你有没有在你的SQL有一个'集团BY'。 – 2012-07-22 03:48:54
还有你的意思是: '
恕我直言'$行['brand_id']'是一个整数而不是数组。 – 2012-07-22 03:53:11