2012-03-12 79 views
0

我想在我的數據庫中回顯超過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 } ?> 
+0

而現在的問題是ID ....? – KingCrunch 2012-03-12 10:09:53

+0

不知道配置與你的功能有什麼關係。也不知道你如何使用查詢功能。也不知道這個問題應該是什麼! – Sgoettschkes 2012-03-12 10:20:41

回答

0

你可以使用這樣一組ID:

$rows['ids'][] = $row; 

然後你可以通過IDS使用

foreach ($rows as $id) 

或直接$rows[] = $row如果你只保留ID。

+0

我在哪裏放置該代碼? – Dale 2012-03-12 11:03:26

0

你總是覆蓋相同的元素$rows['id'] = $row;。你應該做

$rows['id'][] = $row; 

,以顯示你應該反覆$行

foreach($rows['id'] as $id){ 
    echo $id; 
} 
+0

現在沒有任何顯示 – Dale 2012-03-12 10:18:25

+0

@Dale在做這些之後,你必須遍歷'$ rows ['id']' – 2012-03-12 10:22:20

+0

我在哪裏放置代碼? – Dale 2012-03-12 11:03:51