While loop producing weird div behavior

I have the following code running in my site. It is done to show items 2 by 2, with a line break every time an even number is gotten.

This is all within a DIV:

while($info = $items->fetch(PDO::FETCH_ASSOC)) 
{
echo "<div name='item' id='".$info['color_base1']."' class='itemBox'>
<div class='showItem'><a href='items_descr.php?itemId=".$info[id_item]."'>
<img class='itemImage' alt='' src='images/$info[imageMid].jpg'></img></div></div><br />";
echo "<div class='indexItemText'><font class='similarItemsText'>
<a href='items_descr.php?itemId=".$info[id_item]."'>".$info[name]."</a>
<font class='price'> - $".$info[price]."</div>";
$row_count++;
if ($row_count % 2 == 0) 
    {
echo "<br />"; // close the row if we're on an even record
    }

}

The problem is that my resulting CSS is doing something weird. It creates divs for the 1st 2 items and then it creates tags for the following items, to the point that these come out of the container div where they should be loaded...

Any idea of why this could be happening?

Answers


Please try this :-

$html = '';
while($info = $items->fetch(PDO::FETCH_ASSOC)) 
{
    $html.= "<div name='item' id='".$info['color_base1']."' class='itemBox'>
     <div class='showItem'><a href='items_descr.php?itemId=".$info['id_item']."'>
     <img class='itemImage' alt='' src='images/".$info['imageMid'].".jpg' /></div> </div><br />";

    $html.= "<div class='indexItemText'><font class='similarItemsText'>
       <a href='items_descr.php?itemId=".$info['id_item']."'>".$info['name']."</a></font>
       <font class='price'> -$".$info['price']." </font></div>";  

   $row_count++;
   if ($row_count % 2 == 0) 
    {
      $html.= "<br />"; // close the row if we're on an even record
    }
}
 echo $html;

Need Your Help

Ruby storing remote files in Zip using RubyZip

ruby-on-rails ruby amazon-s3 zip rubyzip

I have a model called Image. Images have files attached using Dragonfly that are stored in S3.

How to set the env in rack/test?

ruby rspec sinatra rack webmock

In Sinatra tests, env['SERVER_NAME'] defaults to www.example.com. How can I set this to some arbitrary domain?