将数组转换为以特定方式输出



PHP

    <?php 
    $result = $sth->fetchAll(PDO::FETCH_NUM);
    print_r($result); //or var_dump($result); for more info
    foreach($result as $row){
        $half = array_splice($row,0,5);
        echo implode(" ",$half)."<br /><br />Merchant Offered:<br />".implode(" ",$row);
    }   
    ?>

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

当前输出:https://i.stack.imgur.com/qAtcf.png

如何使其NOT输出第一个大数组:

Array ( [0] => Array ( [0] => Joseph [1] => Dickinson [2] => Need Xbox 360 [3] => 150 [4] => I need one quick! [5] => 2011-09-15 [6] => John [7] => Doe [8] => 149.99 [9] => 2011-09-15 ) [1] => Array ( [0] => Joseph [1] => Dickinson [2] => Need Xbox 360 [3] => 150 [4] => I need one quick! [5] => 2011-09-15 [6] => Jane [7] => Doe [8] => 154.99 [9] => 2011-09-15 ) [2] => Array ( [0] => Joseph [1] => Dickinson [2] => Need Xbox 360 [3] => 150 [4] => I need one quick! [5] => 2011-09-15 [6] => Diana [7] => Matthews [8] => 160.00 [9] => 2011-09-15 ) [3] => Array ( [0] => Joseph [1] => Dickinson [2] => Need Xbox 360 [3] => 150 [4] => I need one quick! [5] => 2011-09-15 [6] => Amanda [7] => Koste [8] => 174.99 [9] => 2011-09-15 ) [4] => Array ( [0] => Warren [1] => Kennan [2] => Need New Sofa [3] => 1000 [4] => Need one quick [5] => 2011-09-15 [6] => Diana [7] => Matthews [8] => 495.99 [9] => 2011-09-15 ) [5] => Array ( [0] => Warren [1] => Kennan [2] => Need New Sofa [3] => 1000 [4] => Need one quick [5] => 2011-09-15 [6] => Amanda [7] => Koste [8] => 489.99 [9] => 2011-09-15 ) ) Joseph Dickinson Need Xbox 360 150 I need one quick!

相反,TO POST输出,如:

Joseph Dickinson Need Xbox 360 150 I need one quick!
Merchant Offered:
2011-09-15 John Doe 149.99 2011-09-15

感谢

尝试类似的

代码

 <?php
    ...
    // Do a loop on each row of your result / repeat the display
    foreach ($result as $row) {
         for ($i=0;$i<=count($row); $i++) {
               echo $row[$i].' ';
               if ($i==6) {
                   echo '<br/><br/>Merchant Offered:<br/>';
               }
         }
         echo '<br/><br/>';
    }

输出为

 Joseph Dickinson Need Xbox 360 150 I need one quick!
 Merchant Offered:
 2011-09-15 John Doe 149.99 2011-09-15
 Joseph Dickinson Need Xbox 360 150 I need one quick!
 Merchant Offered:
 2011-09-15 Jane Doe 149.99 2011-09-15
 ...

两件事:

  • 不确定输出是否正是你所需要的,你真的想在每一行重复用户请求吗?还是你想一次又一次地提供商品?像低于

    Joseph Dickinson Need Xbox 360 150 I need one quick!
    Merchant Offered:
    2011-09-15 John Doe 149.99 2011-09-15
    2011-09-15 Jane Doe 149.99 2011-09-15
    ...
    

    在这种情况下,您需要在人员请求中添加一个标识符来对行进行分组,例如。。。

  • 也许您可以将信息连接到sql语句中,以提高代码的可读性,并避免出现以下行:if($i==6(,这并不能真正代表可以理解的内容。

相关内容

  • 没有找到相关文章

最新更新