我想从我的数据库中回显多于1个id,如何在索引页面中显示多个id?
我的功能:
function query($sql) {
global $conn;
$results = mysql_query($sql, $conn);
$rows = array();
if(!is_bool($results))
while($row = mysql_fetch_assoc($results))
$rows['id'] = $row;
return $rows;
}
我的索引页面:
<?php foreach($funds as $fund) { ?>
<td width="87%" valign="top"><ul id="funds" class="bodycopy2" style="margin:0;">
<li><?php echo $fund['fund']; ?><span class="price"><div align="center" class="h1"><strong><br />R123.45</strong> <br />as at <br />1 January 2012</div></span></li>
<li><?php echo $fund['fund']; ?><span class="price"><div align="center" class="h1"> <strong><br />R200.45</strong> <br />as at <br />1 January 2012</div></span> </li>
<li><?php echo $fund['fund']; ?><span class="price"><div align="center" class="h1"> <strong><br />R150.00</strong> <br />as at <br />1 January 2012</div></span></li>
</td>
</tr>
</table>
<?php } ?>
答案 0 :(得分:0)
你可以使用一组id:
$rows['ids'][] = $row;
然后你可以使用
来查看IDforeach ($rows as $id)
如果您只保留身份证,请直接$rows[] = $row
。
答案 1 :(得分:0)
您始终会覆盖相同的元素$rows['id'] = $row;
。你应该做
$rows['id'][] = $row;
显示你应该在$ rows上重复的id
foreach($rows['id'] as $id){
echo $id;
}