View Single Post
  #2   Spotlight this post!  
Unread 23-06-2007, 16:12
SamC SamC is offline
.
AKA: Sam Couch
FRC #0103 (Cybersonics)
Team Role: Programmer
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Philadelphia, PA
Posts: 583
SamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond repute
Re: Dynamic Tables in PHP

Instead of using an array to hold all of the information, why not use a MySQL (or some other) database? It would be much easier I think, for when you have many more photos to organize in your photo gallery.

Once you have a database setup, just setup the tables in HTML and have PHP code within the table to echo the <a href=" "><img /></a> code and setup a config section that will define how many images you want per page. If I have some time later I will edit this post with an example of what I mean. It is slightly more complex than what you are looking at right now, but in the long run, once you get into more advanced PHP it ill be much more simpler.

EDIT:
Ok, here is some basic code. Anything that is in CAPS would be a MySQL column or row.
PHP Code:
<table>
<tr> 
<?php
//config section
$column_limit 5//change to howver many columns you want
//MySQL information
$server "[insert here]"//url for the mysql server
$DBuser "[insert here]"//database username
$DBpass "[insert here]"//database password
$DB "[insert here]"//actual database name
//column counter
$column_counter 0;

$conn mysql_connect($server,$DBuser,$DBpass); //connect to server
mysql_select_db($DB); //select database
        
$query "SELECT * FROM PICTURES"//select items from column PICTURES
        
$results mysql_query($query);

while(
$row mysql_fetch_assoc($results)) 
        {
        if(
$column_counter == $column_limit)    
        {
        echo 
'</tr><tr>'//End current row, and start a new row
                
$column_counter 0//reset the column counter
        
}
        else {
        echo 
'<td><a href="' .$row[PICTURE_URL]. '" ><img src="' .$row[PICTURE_URL]. '" /></a><br>'//Echo a link to the image, and display the image as well
        
echo 'Added to gallery:' .$row[PICTURE_DATE]. '</td>'//display the dat it was added
        
$column_counter++; //Add one to the counter
        
}
        }
?>
</tr>
    </table>

Last edited by SamC : 24-06-2007 at 02:25.