|
|
|
| Title : |
How to display any array in several rows and columns of a table. Not just
in one column or in alternate rows. This example shows a nice color table
generated with PHP, but can be used with any array values(e.g. Database) |
| Categories : |
Arrays, PHP, Miscellaneous, Beginner Guides, Graphics |
 Andy Krause |
| Date : |
Dec 14th 2000 |
| Grade : |
2 of 5 (graded 10 times) |
| Viewed : |
22305 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Andy Krause |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
On each and every corner you find snippets on how to display every second row e.g. in a
different color. But what, if you want to display a table with 6 rows and 6 colums in different
colors? Here's the solution:
<?
$colors=ARRAY(
"#000000","#000033","#000066","#000099","#0000CC","#0000FF","#003300",
"#003333","#003366","#003399","#0033CC","#0033FF","#006600","#006633",
"#006666","#006699","#0066CC","#0066FF","#009900","#009933","#009966",
"#009999","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99",
"#00CCCC","#00CCFF","#00FF00","#00FF33","#00FF66","#00FF99","#00FFCC",
"#00FFFF");
?>
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<?
for($i=0; $i< count($colors); $i++) {
echo '<td>
<table name="'.$colors[$i].'" width=10 height=10 border="0" bgcolor="'.$colors[$i].'">
<tr>
<td><img src="_blank.gif" width="1" height="1" border="0" alt=""></td>
</tr>
</table>
</td>';
if ( (($i+1) % 6) == 0 ) echo $newrow="</tr><tr>"; // change 6 to 8 and see
}
?>
</tr>
</table>
If you replace the array of colors with any database generated value, you can generate a
table of images like an album nicely without manually fiddling with the code.
Enjoy and let me know, if it helps.
n-dee
|
|
| Using PHP im HTML image tags Categories : PHP, HTML and PHP, Graphics, Beginner Guides | | | Link Submition - Allow your visitors to submit links to the site. Categories : PHP, Arrays, Filesystem, Beginner Guides | | | Simple way of scaling any image to fit either given width or height. Categories : PHP, Graphics, Arrays | | | Form Submission Using Array's Categories : PHP, HTML and PHP, Beginner Guides, Arrays | | | PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP, Graphics, GD image library, Beginner Guides | | | Simple PHP Bar Graph using GD library Categories : PHP, GD image library, Graphics, Arrays | | | Human readable PHP password generator Categories : PHP, Security, Beginner Guides, Arrays | | | Random text quote Categories : PHP, Arrays, Beginner Guides | | | Simple image counter Categories : PHP, Graphics, Filesystem, Beginner Guides | | | HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout. Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs | | | This script will read all images from a folder and read the files into an array. It uses rand() to get a random number. It will display a random image from the image folder given. Categories : PHP, Arrays, Graphics, Filesystem | | | PHP Image Validation Class - test if a specific file is of a certain image type without relying on the said file extension. Categories : PHP, PHP Classes, Data Validation, Graphics, Beginner Guides | | | Beginners Array Functions Categories : PHP, Beginner Guides, Arrays | | | How to preset a text string in a textarea input field Categories : HTML, HTML and PHP, PHP, Beginner Guides | | | Filling an array with files from any given directory. This example is for the current PHP script's directory. Categories : PHP, Arrays, Filesystem | |
|
|