0

管理员:请创建图像网址作为图像 我试图实现以下输出:

//
    Joseph Dickinson
    Title: Need Xbox 360
    Comment: I need one quick!
    on 2011-09-15
    John Doe 149.99
    Jane Doe 154.99
    Diana Matthews 160.00
    Amanda Koste 174.99
//

目前,我为每个报价都写了“Joseph Dickinson”这个名字,比如“John Doe 149.99”或“Jane Doe 154.99”。我想要它一次,标题如“需要 Xbox 360” http://i.stack.imgur.com/ERLbX.png

此页面通过 php 文件收集此信息:

<?php require_once('inc/db/dbc.php'); ?>
<?php
#GET User (Buyer) Info and General Listing Info
$pdo = new PDO($h1, $u, $p);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth = $pdo->prepare('
  SELECT uFName, uLName, listTitle, listCmt, listDt, mBCFName, mBCLName, 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
  LIMIT 0,5
;');
$sth->execute(array());

?>

我正在使用的 PHP

    <?php $usrBrowser = $_SERVER['HTTP_USER_AGENT']; $todayDt = date('Y-m-d');  ?>
    <form id="AddListing" method="post" action="#">
        <input type="hidden" name="theUserID" value="" /> <br>
        Product Wanted: <input type="text" name="ListingTitle" /> <br>
        Listing Length:<?php require_once('inc/php/listingLengths.php'); ?>
        &nbsp;&nbsp;&nbsp;Cost: <input type="text" name="ProductAskingPrice" /> <br>
        &nbsp;&nbsp;&nbsp;Shipping: <input type="text" name="ProductAskingShipAmount" /> <br>
        &nbsp;&nbsp;&nbsp;Additional Comment: <input type="text" name="ListingComment" /> <br>  
        <input type="hidden" name="ListingDateOfEntry" value="<?php echo $todayDt; ?>" /> <br>  
        <input type="hidden" name="ListingUserBrowserType" value="<?php echo $usrBrowser; ?>" /> <br>
        <input type="submit" value="List" />
    </form>
    <?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("<br> ",$half)."<br />".implode(" ",$row);
    }   
    ?>

我如何让它以我上面列出的方式输出?使用数组索引会更容易吗?我如何实现上面的 // // ? http://i.stack.imgur.com/dBhyx.png

4

1 回答 1

0

试试这个:

foreach($result as $row)  
  {  
  print $row[0] . ' ' . $row[1] . '<br>Title: ' . $row[2] . '<br>Comment: ' . $row[3] ...   . '<br>';
  }  

如果您更改$result = $sth->fetchAll(PDO::FETCH_NUM);$result = $sth->fetchAll(PDO::FETCH_ASSOC);您可以使用更具可读性的代码获得相同的结果:

print $row['uFName'] . ' ' . $row['uLName'] . '<br>Title: ' . $row['listTitle'] . '<br>Comment: ' . $row['listCmt'] ... . '<br>';
于 2011-10-04T01:07:27.093 回答