[英]Echoing more than 1 id
我想從數據庫中回顯1個以上的ID,如何在索引頁面中顯示1個以上的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 } ?>
您可以使用ID數組,例如:
$rows['ids'][] = $row;
然后,您可以使用
foreach ($rows as $id)
或者,如果僅保留ID,則直接$rows[] = $row
。
您總是覆蓋相同的元素$rows['id'] = $row;
。 你應該做
$rows['id'][] = $row;
顯示您應該在$ rows上進行迭代的id
foreach($rows['id'] as $id){
echo $id;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.