3 columns in each row in my table ....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
VisionsOfCody
Forum Commoner
Posts: 30
Joined: Sat Mar 01, 2003 1:19 pm
Location: France

3 columns in each row in my table ....

Post by VisionsOfCody »

hi
i'd like to ouput my query results as a table that has 3 cols in each row.
It's for a photo gallery which has 3 columns of thumbnails that link to the big photos
I have no problems setting up a 'while()' loop to do the rows, but how do i do the 3 columns across each row ?
At a guess i'd say i'd have to do a sort of sub-loop within each table row - but how do i split the results up into bunches of three and assign them to each of the three cells in each row ??
If there's a "standard" way of doing this, could someone tell me ?
.... or a workaround .... or just an idea
thanks
User avatar
Wayne Herbert
Forum Commoner
Posts: 34
Joined: Tue Apr 29, 2003 3:13 pm
Location: Houston, Texas

Post by Wayne Herbert »

I've written a php script which does pretty much as you want. It runs this site:

http://www.herbhost.com/seasia/index.htm

Not only does it lay out the thumbnails 4 up, it limits the total thumbs per page to 28 (for non high speed connection page loads), and it also prevents orphan pages with only a few photos, that is, if there are 36 or fewer photos on the last page or any page, then they all go on one page.

The script is a bit long to post here, but if you are interested, email me, and I will supply you with the three scripts that drive the site.

The following sample code will put every record that you have selected on the same page, 3 up, and will blank fill any table cells in the last row.

Code: Select all

<?php
// want to generate the last cells in the table if not a multiple of 3
$notdone = true;
echo "<table>"; 
while $notdone
  {
  echo "<tr>"; // define the row
  for ($j = 1; $j <= 3; $j++)
    {
    // last row of pix may have less than 3 thumbs so fill
    // so create cell only
    if ($row = @ mysql_fetch_array($result))
      {
      echo "<td valign=top WIDTH="33%">"; // create the cell
      // and build the stuff you want
      } // if got a row
    else // no more rows - make a blank cell entry
      {
      $notdone = false;  // end the process
      echo "<td valign=top WIDTH="33%">";
      echo "<br>  ";
      }
    echo "</td>"; // end the cell definition
    } // end for j
  echo "</tr>"; // end the row
  } // while not done
VisionsOfCody
Forum Commoner
Posts: 30
Joined: Sat Mar 01, 2003 1:19 pm
Location: France

Post by VisionsOfCody »

that is BRILLIANT - thanks :D

just one thing though - what does the "@" mean in this line ? :

if ($row = @ mysql_fetch_array($result))

i don't think i've seen that before
thanks again
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

the @ sign suppresses errors so that if it doesn't get a value it doesn't put a dirty error message on the screen to the user
VisionsOfCody
Forum Commoner
Posts: 30
Joined: Sat Mar 01, 2003 1:19 pm
Location: France

Post by VisionsOfCody »

ooooh - i Like that !!
thanks again both :D :D :D
User avatar
Wayne Herbert
Forum Commoner
Posts: 34
Joined: Tue Apr 29, 2003 3:13 pm
Location: Houston, Texas

Post by Wayne Herbert »

VisionsOfCody wrote:that is BRILLIANT - thanks :D
Eh?? Er... ahem... thanks!... :mrgreen: ... but, I suspect that these lines of code have been written millions of times before I ever wrote them down. Now, six dimensional arrays are a bit more uncommon.
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

mmmm multi demensional 8O

(homer simpson voice)
User avatar
Wayne Herbert
Forum Commoner
Posts: 34
Joined: Tue Apr 29, 2003 3:13 pm
Location: Houston, Texas

Post by Wayne Herbert »

JPlush76 wrote:mmmm multi demensional 8O
I'm OK... and so am I! :D :) :o :wink: :lol: :?
Post Reply