Use id as multiple when displaying output in table format to make new row

Dear all,

I have a javascript/html/php code for displaying images from my database. I’d like to put these in a

where after a row of 50 images, it drops to a new row, based on it’s id (which I have set to auto increment). In other words it would look something like this -
Image 1, Image 2, Image 3 ... Image 49, Image 50
Image 51, Image 52, Image 53 ... Image 99, Image 100
Image 101, Image 102, Image 103 ... Image 149, Image 150

…and so on. Each image is actually made up of 4 smaller images, which are positioned using a javascript code unique to each element.

It’d need to be “self-governing” as it were, as I wouldn’t be able to checkout when each time it reached 50 and needed a new row.
So my two concerns are how to replicate the unique info for each image based on it’s id and then how to get it to jump to the next 50 after that.
I appreciate this is a big ask, so I’m more than happy just to be pointed in the direction of a good tutorial rather than have someone type it out (unless of course you have something to hand), but every time I search for a bit of help in this area I come up against a brick wall.
Thank You in advance, Toastie.

Hi. Since you mentioned that you have image info stored in the database, I am posting a short example that may help you in your task. Though I am not sure if this is exactly what you need.
[php]<?php

$s=’’;
$n=50; // number of columns in html table

// query database records with image info

$r=mysql_query(“select ImageName, ImageURL, ID from MyImages order by ID”);

for($i=0;$i<mysql_num_rows($r);$i++){
$f=mysql_fetch_array($r);

if($i%$n==0) $s.='<tr>';
$s.='<td><a href="'.$f["ImageURL"].'">'.$f["ImageName"].'</a></td>';
if($i%$n==($n-1)) $s.='</tr>';

}

// if last table row have less than $n columns, adding remaining cells (blank)

$k=$i%$n;
if($k){
for($i=$k;$i<$n;$i++){
$s.=’

’;
}
$s.=’’;
}

if($s!=’’) $s=’

’.$s.’
’;

echo $s;

?>[/php]

As you can see, in this example we’re querying all the records from the database table, and then displaying them in a table row by row (each row contain exactly 50 records, except maybe last row).

That’s great, thankyou, I’d say it was about half way there to what I need, so i’ll take this and have a go at the rest, thankyou again.

Sponsor our Newsletter | Privacy Policy | Terms of Service