MySql fetch array with div to make a grid list -not rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andrewburgess
Forum Newbie
Posts: 3
Joined: Fri Jun 20, 2008 8:17 pm

MySql fetch array with div to make a grid list -not rows

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: MySql fetch array with div to make a grid list -not rows

Post by Kieran Huggins »

you could create a series of inline divs:

http://www.alistapart.com/articles/practicalcss/
andrewburgess
Forum Newbie
Posts: 3
Joined: Fri Jun 20, 2008 8:17 pm

Re: MySql fetch array with div to make a grid list -not rows

Post 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&#058;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");
   ?>&nbsp;</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]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: MySql fetch array with div to make a grid list -not rows

Post 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.
andrewburgess
Forum Newbie
Posts: 3
Joined: Fri Jun 20, 2008 8:17 pm

Re: MySql fetch array with div to make a grid list -not rows

Post 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..
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: MySql fetch array with div to make a grid list -not rows

Post 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.
Post Reply