views:

232

answers:

3

Hello there , I have some images uploaded in a folder on my server, and their paths are stored in a table in my database. Whats the best way to display this images on the browser(as a gallery)?Should I use jqery or maybe codeigniter could do the job?Please provide some examples or resources..Thanks!

A: 

Just a very simple query on the table will do, I think your getting confused as to what jquery and codeigniter do! For something like this just use some simple PHP:

<?php
$query = mysql_query("SELECT * FROM table");
while ($row = mysql_fetch_array($query)) {
    echo '<img src="'.$row['file_path'].'" alt="" />';
}
?>
fire
thanks fire...I'm probably a bit confused...can you suggest a good way to navigate through the images?
rabidmachine9
+1  A: 

I tend to agree that you're probably a little bit confused. There are two components that have to happen here.

  1. You'll need server-side code (e.g. plain PHP or PHP + CodeIgniter Framework) to pull the information from your database and render some HTML / JavaScript to present that content to the user.
  2. You'll need client-side code to turn your marked-up HTML into some kind of gallery, assuming you want it "active".

There are almost an infinite number of ways to perform #1, and they are totally dependent on your database configuration, server, etc. Using CodeIgniter with Active Record, and assuming that you already have an active database connection, the PHP would look something like this:

<?php
    $photos = $this->db->get('photo_table'); // Retrieve photos from DB
    $photos = $photos->result_array();

    foreach($photos as $photo) {
        echo '<img src="' . $photo['url'] . '" alt="' . $photo['alt'] . '" />';
    }
?>

Number two is most easily handled by using something like jQuery + ColorBox. There are literally hundreds of gallery/slideshow/photo plugins for jQuery. If you're interested in looking around, there are a bunch here.

ebynum
A: 

Why not using an existing gallery on your server which do all the jobs for you? Have a look on Gallery2 or phTagr. Both galleries are using PHP MVC frameworks - maybe they can used as inspiration, too :-)

xemle