以某种方式输出数组元素

发布于 2024-12-07 21:28:20 字数 2542 浏览 1 评论 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” https://i.sstatic.net/ERLbX.png

此页面通过 php 收集此信息file:

<?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);
    }   
    ?>

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

Admin: Please create image urls as images
I'm trying to achieve the following output:

//
    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
//

Currently, I get the name "Joseph Dickinson" written for each offer like "John Doe 149.99" or "Jane Doe 154.99". I want it ONCE for each, Title like "Need Xbox 360"
https://i.sstatic.net/ERLbX.png

This page gathers this info through a php file:

<?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 I'm Using

    <?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'); ?>
           Cost: <input type="text" name="ProductAskingPrice" /> <br>
           Shipping: <input type="text" name="ProductAskingShipAmount" /> <br>
           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);
    }   
    ?>

How do I get it to output in that manner I listed above? Would it be easier to use array indexes? How do I achieve the // // above?
https://i.sstatic.net/dBhyx.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笔绘流年 2024-12-14 21:28:20

试试这个:

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);< /code> 您可以使用更具可读性的代码获得相同的结果:

print $row['uFName'] . ' ' . $row['uLName'] . '<br>Title: ' . $row['listTitle'] . '<br>Comment: ' . $row['listCmt'] ... . '<br>';

Try this:

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

If you change $result = $sth->fetchAll(PDO::FETCH_NUM); into $result = $sth->fetchAll(PDO::FETCH_ASSOC); you can get the same result with more readable code:

print $row['uFName'] . ' ' . $row['uLName'] . '<br>Title: ' . $row['listTitle'] . '<br>Comment: ' . $row['listCmt'] ... . '<br>';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文