A primary school website I am working on is completely database driven and as part of the site the school wishes a series of photo galleries. For various reasons I cannot use any of the ready made photo galleries. I have managed to write the code for uploading the pictures into a directory and creating the thumbnails. Also for writing the required information into a database.

I can retrieve the required information from the database to display the thumbnails but no matter how I try I can only get them to display in a single column. Can someone give me some code (with explanations) to display my thumbnails in say 3 rows x 4 columns per page.

Hi Camdes,
I must be missing something. If you managed to write a thumbnail creating code there must be something awfully difficult about making the 3x4 table.

Anyways, here's my code (cut from my existing script that displays links in a grid):

$columnsNumber = 4;
  // there will be as many rows as necessary
  print '<table class="links_table"><tr>';
  $i = 1;
  while ($link = mysql_fetch_assoc($links_db)) {
    print '<td>yourthumbnail</td>';

    if ( ($i % $columnsNumber) == 0)
      print "\n</tr><tr>\n";

  if ( (($i-1) % $columnsNumber) != 0 )
    print "<td colspan=".($columnsNumber- (($i-1) % $columnsNumber))."></td>\n\n";

  print '</tr></table>';

It's so short that I don't thing comments are necessary. However, let me know if you need them.

Thank you for the code, I will attempt it tonight.
When I said I had managed to write the code for the thumbnails, what I meant was that using other code and tutorials I had managed to cobble something together that would create them. Unfortunatly my programming skills are taken from the Idiots Guide books on HTML and PHP. Not from any great knowledge of programming.

Hi this is really useful code. i want to pagination if u can help me