2014-01-09 65 views
0

從MySQL的所有結果我使用該SQL查詢來從不同的表問題與顯示使用PHP

<? 
$sql = "SELECT gtem.gname AS itmnme, gvendor.gname AS vendor, gtem.col AS qty 
FROM gpopackageline 
LEFT JOIN gpo ON gpo.gpoid = gpopackageline.gpoid 
LEFT JOIN gtem ON gpopackageline.gtemid = gtem.gtemid 
LEFT JOIN gvendor ON gitem.gvendorid = gvendor.gvendorid 
WHERE gpopackageline.gpoid='".$sdo['swelid']."' "; 
$row = dblib_get_row_list($sql); 
?> 
<td class="contents51" width="100%"><?=$row['itmnme']?> </td> 
<td class="contents51" width="100%"><?=$row['vendor']?> </td> 
<td class="contents51" width="100%"><?=$row['qty']?> </td> 

問題是我只得到1和第一結果印刷得到的結果。 當我在phpMyAdmin測試查詢我得到的所有結果 是否anyboby可以用這個 幫忙,謝謝

+0

你的'dblib_get_row_list'函數是怎麼樣的? –

+0

什麼是「dblib_get_row_list」? – dwjv

+0

也許你需要每個$行的循環? –

回答

1

你需要遍歷的結果,或者由while,或foreach - 這取決於你的邏輯。

例如

<? 
$sql = "SELECT gtem.gname AS itmnme, gvendor.gname AS vendor, gtem.col AS qty 
FROM gpopackageline 
LEFT JOIN gpo ON gpo.gpoid = gpopackageline.gpoid 
LEFT JOIN gtem ON gpopackageline.gtemid = gtem.gtemid 
LEFT JOIN gvendor ON gitem.gvendorid = gvendor.gvendorid 
WHERE gpopackageline.gpoid='".$sdo['swelid']."' "; 
$getRows = dblib_get_row_list($sql); //Assuming this returns everything in an assoc array 
foreach($getRows as $row) { 
?> 
<td class="contents51" width="100%"><?=$row['itmnme']?> </td> 
<td class="contents51" width="100%"><?=$row['vendor']?> </td> 
<td class="contents51" width="100%"><?=$row['qty']?> </td> 
<?php 
} 
?> 
+0

謝謝worksforeach –

+0

沒有問題的所有:)很高興成爲幫助。 –

0

我不知道你是什麼dblib_get_row_list的回報。如果它返回數組,那麼它應該按照你的預期工作。

<? 
    $sql = "SELECT gtem.gname AS itmnme, gvendor.gname AS vendor, gtem.col AS qty 
    FROM gpopackageline 
    LEFT JOIN gpo ON gpo.gpoid = gpopackageline.gpoid 
    LEFT JOIN gtem ON gpopackageline.gtemid = gtem.gtemid 
    LEFT JOIN gvendor ON gitem.gvendorid = gvendor.gvendorid 
    WHERE gpopackageline.gpoid='".$sdo['swelid']."' "; 
    $result = dblib_get_row_list($sql); 
    foreach($result as $row){ 
    echo "<td class='contents51' width='100%'>".$row['itmnme']."</td>"; 
    echo "<td class='contents51' width='100%'>".$row['vendor']."</td>"; 
    echo "<td class='contents51' width='100%'>".$row['qty']."</td>"; 

    } 
+0

感謝作品「foreach」 –