Three shop offers in row

2019-06-13 16:53发布

    if(count($offer_list['item']) > 0)
{
  $main_content .= '<table cellspacing="2" cellpadding="2" width=30>';
  foreach($offer_list['item'] as $item)
  {
    $main_content .= '<td class="shop">
    <a class="shop" style="display: block;" href="/shop/item/id/'.$item['id'].'">
    <center><img src="item_images/'.$item['item_id'].'.gif"><br><font color="white"><b>'.$item['name'].'</font></b><font color="red"> <b> '.$item['points'].' points</font></b>';
    if(!$logged)
    {
      $main_content .= '<p><b><a href="/account">[Login to buy]</a></b>';
    }
    else
    {
  $main_content .= '<br><b><font size=1 color="white">Your points balance is: '.$user_premium_points;
      $main_content .= '<br><font color="white"> <fieldset class="shop"><legend>DESCRIPTION</legend>'.$item['description'].'</fieldset></font><br><font color="white"><b> [Click to buy] </b></font></form> </a></center></td>';
    }
    $main_content .= '';
  }
  $main_content .= '</tr></table>';
}

How to make it like only three offers in row? NOW I have one row and all offer is in one line; I just want to show max three td in tr and loop.

1条回答
成全新的幸福
2楼-- · 2019-06-13 17:47

if you only want 3 tds in a row, build it into your loop:

    //opener

    <table>
    //1st row
    foreach($offer_list['item'] as $item) {


    content.= <tr>;
    content.= <td>$item[id]</td><td>$item[image]</td><td>$item[etc]</td>;
    content.= <tr>;

    //2nd row
    content.= <tr>;
    content.= <td>$item[description]</td><td>$item[etc]</td><td>$item[etc]</td>;
    content.= <tr>;

    }
    content.=</table> //or div, etc

however it sounds like you want to position elements around like a product? Use inline divs for this. (no point in a example unless you elaborate what you want to do..)

查看更多
登录 后发表回答