简体   繁体   中英

sql query & foreach and <td>

Im trying to get auctions info and put into so to do this i think i need have result in string not in array and i do next

         $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);

and result is `string(80) "150031,u0001,2013-08-19 16:08:03,no,833,Title of Item"

but here show only 1 result since in sql query i have multiple result for multiple users

after geting result i need go and foreach <tr><td>ID of AUCTION:(put here ID of item)</td></tr>Title:(title of item) and etc

any ideas?

Since you said

we have select query with key :) , if under sellectAssoc() i enter a query without key will not work

If you really only get one record back from that query you will have to either modify you query so you get multiple records at once or do the query several times.

For each record you can then use the following to fill a single table row:

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 ...
}

I left out the captions 'ID of AUCTION:' and 'Title:' in the table cells. They should be used as headings in a separate table row above the actual table body like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM