communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "array handling" - download "entries per row"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

array handling - entries per row was created/last modified on Mon 05 Jul 2004 7:39 PM

show images or database entries in a table with as many columns you specify.

ideal for an image gallery.


<?php

// your data in an array
$images = array(
             
'some',
             
'data',
             
'or',
             
'images',
             
'you',
             
'want',
             
'to',
             
'show',
             
'with',
             
'as',
             
'many',
             
'entries',
             
'per',
             
'row',
             
'as',
             
'you',
             
'specify');

// how many entries per row
$per_row = 3;

echo
'
<table>'
;

$count = 0;

for(
$x = 0; $x < count($images); $x++)
{
     if(
$count == 0)
     {
         echo
'
     <tr>'
;
     }

     echo
'
         <td>'
.$images[$x].'</td>';

     
$count++;

     if((
$count == $per_row) || ($images[$x] == end($images)))
     {
         echo
'
     </tr>'
;
         
$count = 0;
     }
}

echo
'
</table>'
;

?>

learn more about some of the PHP functions used in this snippet: array, count, echo, end, for

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari