我使用此SQL查询从不同的表中获取结果
<?
$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中测试查询时,我得到了所有结果 任何人都可以帮忙解决这个问题 谢谢
答案 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
}
?>
答案 1 :(得分: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>";
}