View Full Version : Dynamically populate a table

08-11-2009, 04:28 PM
Im building a dynamic photo gallery with pagination and am looking for help or a tutorial on populating a table with say 20 photos per page(similar to an amazon results page)im cool(for now) with the pagination part but cant find any info on dynamically populating a table. Im looking for something like 4 columns down 5 rows across at the moment its just 20 vertical images :(
Here is the test code thats producing the 1 column 20 row table:

$query= "SELECT * FROM photos WHERE user_id = '$id'";
$result= mysql_query($query)or die('couldnt query');
$table = "<table width=\"10%\" border=\"1\">";
while($row = mysql_fetch_array($result)){
$table .= " <tr>
<td><img src=photos/sml_".$row[image].'> </td></tr><br />';

$table .= "</table>";

echo $table;

now how do i make it go :

pic pic pic pic pic

pic pic pic pic pic

pic pic pic pic pic

any ideas would be great :)

08-12-2009, 01:01 AM
i have done this in the past this using css. i actually use divs. a containing div and a 'display' div

.container{ width:800px;}
.display{ width:200px; float:left:};

rough idea of code but you should get what i mean

"echo<div class= \"container\">";
// then echo out the results in a loop as

echo "<div class= \"display\">";
// your info here blah blah;

echo "</div>";
} end loop
echo "</div>";

concanted normally but i put it like this for clarity ( i hope)

08-12-2009, 07:20 PM
great thanks alot will try get it working then post up code