I have a for each loop that displays books with information, one on top the other, I would prefer to present these books in a grid (5rows x 5columns). I just can't figure out how to do this.
Can anyone please help me with this?

here is the code:

function display_books($book_array)
{
  //display all books in the array passed in
  if (!is_array($book_array))
  {
     echo '<br />No books currently available in this category<br />';
  }
  else
  {
    //create table
    echo '<table width = \"100%\" border = 0>';

//create a table row for each book    
foreach ($book_array as $row)
{
  $url = 'show_book.php?isbn='.($row['isbn']);
  echo '<tr><td>';
  if (@file_exists('images/'.$row['isbn'].'.jpg'))
  {
    $title = '<img src=\'images/'.($row['isbn']).'.jpg\' border=0>';
    do_html_url($url, $title);
  }
  else
  {
    echo '&nbsp;';
  }
  echo '</td><td>';
  $title =  $row['title'].' by '.$row['author'];
  do_html_url($url, $title);
  echo '</td></tr>';
}
echo '</table>';
  }
  echo '<hr />';
}
    function display_books($book_array)
    {
      //display all books in the array passed in
      if (!is_array($book_array))
      {
         echo '<br />No books currently available in this category<br />';
      }
      else
      {
        //create table
        echo '<table width = \"100%\" border = 0><tr>';
    
    //Make loop variable to count cells across
    $I = 0;
    
    //create a table row for each book    
    foreach ($book_array as $row)
    {
      //If $I divided by 5 has a remainder of 0, end this row and make a new one
      if (($I % 5) == 0) {
        echo '</tr><tr>';
      }
    
      echo '<td>';
    
      $url = 'show_book.php?isbn='.($row['isbn']);
      echo '<table width = \"100%\" border = 0><tr><td>';
      if (@file_exists('images/'.$row['isbn'].'.jpg'))
      {
        $title = '<img src=\'images/'.($row['isbn']).'.jpg\' border=0>';
        do_html_url($url, $title);
      }
      else
      {
        echo '&nbsp;';
      }
      echo '</td><td>';
      $title =  $row['title'].' by '.$row['author'];
      do_html_url($url, $title);
      echo '</td></tr></table>';
    
      echo '</td>';
      $I++;
    }
    echo '</tr></table>';
      }
      echo '<hr />';
    }

    Hope this helps,
    Tom

      I've been pulling my hair out on this one

      thanks for the code

      -Sean

        Write a Reply...