php - Image gallery with codeigniter


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 jQuery or maybe CodeIgniter could do the job?




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:

    $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.




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:

$query = mysql_query("SELECT * FROM table");
while ($row = mysql_fetch_array($query)) {
    echo '<img src="'.$row['file_path'].'" alt="" />';

People are also looking for solutions to the problem: php - Building a website on top of wordpress


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.