Page 1 of 1
MySql fetch array with div to make a grid list -not rows
Posted: Sat Jun 21, 2008 4:29 am
by andrewburgess
Hi,
I have this image gallery in php that list thumbnail images from my database. I list the thumbnails with mysql fetch array in a table and that gives me thumbnails in rows. But the page would be so much more efficient if the thumbnails would be arranged in a grid layout -like image.google.com. How could i do this?
Thanks for helping out,
Andrew
Re: MySql fetch array with div to make a grid list -not rows
Posted: Sat Jun 21, 2008 4:41 am
by Kieran Huggins
Re: MySql fetch array with div to make a grid list -not rows
Posted: Sat Jun 21, 2008 7:56 am
by andrewburgess
Exactly,
But how would my code look like?
Right now it looks like this:
Code: Select all
[color=#4080BF]<?php
$sql = "SELECT im_id, im_title, im_thumbnail, DATE_FORMAT(im_date, '%Y|%m|%d') AS im_date
FROM images ";
if ($album != '') {
$sql .= "WHERE im_album_id = $album ";
}
$sql .= "ORDER BY im_title ";
$result = mysql_query($sql . "LIMIT $offset, $imagePerPage") or die('Error, list image failed. ' . mysql_error());
?>
<table width="600px" border="0" align="left" cellpadding="2" cellspacing="1">
<tr>
<td align="left">Image </td>
<td width="80" align="center">Date</td>
<td width="100" align="center">Action</td>
</tr>
<?php
if (mysql_num_rows($result) == 0) {
?>
<tr>
<td class="colored">No images found.</td>
</tr>
<?php
} else {
while ($row = mysql_fetch_assoc($result)) {
extract($row);
?>
<tr>
<td align="left" class="colored"><a href="?page=image-detail&imgId=<?php echo $im_id; ?>"><img src="../viewImage.php?type=glthumbnail&name=<?php echo $row['im_thumbnail']; ?>" border="0"><br>
<?php echo $row['im_title']; ?></a></td>
<td width="80" align="center"><?php echo $im_date; ?></td>
<td width="100" align="center"><a href="?page=image-edit&imgId=<?php echo $im_id; ?>">Edit</a> | <a href="javascript:deleteImage(<?php echo "'$album', $im_id"; ?>);">Delete</a></td>
</tr>
<?php
} // end while
}
?>
<tr>
<td align="left"> <?php
$result = mysql_query($sql);
$totalResults = mysql_num_rows($result);
echo getPagingLink($totalResults, $pageNumber, $imagePerPage, "page=image-list&album=$album");
?> </td>
</tr>
<tr>
<td align="left"><input type="button" name="btnAdd" value="Add Image" onclick="window.location.href='index.php?page=add-image&album=<?php echo $album; ?>';" /></td>
</tr>
</table>[/color]
Re: MySql fetch array with div to make a grid list -not rows
Posted: Sat Jun 21, 2008 12:09 pm
by califdon
First, for future reference, please use [syntax=php]...[/syntax] tags around any php code that you post here, as I have done for you, above.
Are you familiar with CSS? If you are, Kieran's reference should be just what you need. If you're not, there's something of a problem, because you need to rewrite your page to incorporate CSS, and most of the contributors to this forum aren't willing to rewrite entire scripts for people.
Re: MySql fetch array with div to make a grid list -not rows
Posted: Sat Jun 21, 2008 5:38 pm
by andrewburgess
I know css well but i dont know how to use that php function. Ive googled this, nowhere is there an example of an array with divs..
Re: MySql fetch array with div to make a grid list -not rows
Posted: Sat Jun 21, 2008 6:33 pm
by califdon
andrewburgess wrote:I know css well but i dont know how to use that php function. Ive googled this, nowhere is there an example of an array with divs..
Which php function are you referring to? And I'm not sure why you're interested in "an array with divs".
With your knowledge of css, you would merely replace the HTML table tags with css tags, as explained in the reference that Kieran gave you. That is, instead of your <tr> and <td> tags, you would send the <div> tags. Of course, that would be for the repeating part of it, you would need to add the beginning and ending css tags before and after your while() block.