获取foreach()循环以给定方式显示数组输出

时间:2011-09-21 16:02:11

标签: php mysql arrays multidimensional-array

SQL:

SELECT uFName, uLName, listTitle, listPropPrice, listCmt, listDt, mFName, mLName, moAmt, moDtOff
FROM User U, Listing L, Merchant M, MerchantOffer MO
WHERE U.uID = L.uID
and L.listID = MO.listID
and M.mID = MO.mId

PHP

    <?php 
    $result = $sth->fetchAll();
    print_r($result); //or var_dump($result); for more info
    foreach($result as $row){
        print_r($row);
    }   
    ?>

Kolinks输出:

enter image description here

为什么要重复两次?

1 个答案:

答案 0 :(得分:0)

试试这个:

$half = array_splice($row,0,5);
echo implode(" ",$half)."<br /><br />Merchant Offered:<br />".implode(" ",$row);

基本上,它提取前五个值并用空格连接它们,然后放入“Merchant Offered”文本,然后连接剩余的值。