sql查询& foreach和

时间:2013-08-23 08:37:29

标签: php mysql sql

我试图获取拍卖信息并投入到这样做我认为我需要结果字符串不在数组中我会做下一步

         $aUserData = DBC::$slave->selectAssoc(" 
     SELECT 
    s.id_auction                           AS _key_,
    s.id_auction                           AS id,
    s.seller_user_name                         AS user_name,
    s.end_date_time                        AS finish_date,
    s.suspended                            AS active,
    s.id_category                          AS category,
    s.title                            AS title
    FROM auctions_search                       AS s
    WHERE TRUE
    AND s.status        = 'active'
    AND s.suspended         = 'no'
    ");
        foreach ($aUserData as $iKey => $nUserID)
     {
     if (!isset($aUserData[$nUserID]))continue; 

     }
                 $nUserID = implode(',',$nUserID);

     Tools::printPre($nUserID);

,结果是`string(80)“150031,u0001,2013-08-19 16:08:03,no,833,Item of item”

但是这里只显示了1个结果,因为在sql查询中我有多个用户的多个结果

在确定结果后,我需要去预测<tr><td>ID of AUCTION:(put here ID of item)</td></tr>Title:(title of item) and etc

任何想法?

1 个答案:

答案 0 :(得分:1)

既然你说过

  

我们用key :)选择查询,如果在sellectAssoc()下输入一个   没有密钥的查询将无法正常工作

如果您真的只从该查询中获得一条记录,则必须 修改您的查询,以便您一次获得多条记录多次执行查询。

对于每条记录,您可以使用以下内容填充单个表格行:

foreach ($aUserData as $iKey => $nUserID){ // for each record found ...
  $str="<tr id='$iKey'><td>".join('</td><td>',$nUserId)."</td></tr>";
  Tools::printPre($str); // using your framework to print the line ...
}

我在表格单元格中省略了字幕'AUCTION ID'和'Title:'。它们应该作为标题用在上面上面的实际的表体中,如

<tr><th>ID of AUCTION</th><th>Title</th> ... </tr>