Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7583601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:43:11+00:00 2026-05-30T18:43:11+00:00

Trying to build a dynamic gallery that is loaded via AJAX. I’m trying to

  • 0

Trying to build a dynamic gallery that is loaded via AJAX.

I’m trying to get it to build a ul with as many list items as there are pictures, because each gallery has a different amount of images… something like this:

<ul id="foo">
 <li><a href="javascript:void(0);"><img src="../images/portfolio/foo/001.jpg></a></li>
 <li><a href="javascript:void(0);"><img src="../images/portfolio/foo/002.jpg></a></li>
</ul>
<div class="description">FOO TITLE / DESCRIPTION</div>

<ul id="bar">
 <li><a href="javascript:void(0);"><img src="../images/portfolio/bar/001.jpg></a></li>
 <li><a href="javascript:void(0);"><img src="../images/portfolio/bar/002.jpg></a></li>
 <li><a href="javascript:void(0);"><img src="../images/portfolio/bar/003.jpg></a></li>
</ul>
<div class="description">BAR TITLE / DESCRIPTION</div>

I’m not familiar enough with PHP to build in the foreach to the function I’ve built. Any help? Here is what I have so far (note the array I have is a temporary solution… it doesn’t work if the project has less/more than the 4 that I’ve listed in the array):

<?php function generateProject($projTitle,$projDesc) {

$proj = $_GET['proj'];

echo '<ul id="'.$proj.'">';

$array = array('001','002','003','004');

    foreach($array as $picture)
    {
        echo '<li><a href="javascript:void(0);"><img src="../images/portfolio/'.$proj.'/'.$picture.'.jpg"';
        echo '</li>';
    }

echo '</ul>';

echo '<div class="description">'.$projTitle.' <span class="slash">&nbsp;/&nbsp;</span>'.$projDesc.'</div>';

} ?>


<?php
    generateProject(
    'deadAWESOME',
    'Gargoyles. Dusty leather tomes. Hidden rooms. Coffee.');
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:43:13+00:00Added an answer on May 30, 2026 at 6:43 pm

    First of all, it’s kind of insecure to take the $proj path directly from $_GET. You should check it against an array of acceptable values or a regular expression before placing it into the URLs. In this case as long as the web server’s document root is setup correctly, not much damage could be done. But it’s a good habit to be in to protect your paths.

    $proj = $_GET['proj'];
    
    // Method 1:  regex
    // Test that proj is only lowercase letters...
    if (!preg_match("/^[a-z]+$/", $proj)) {
       // Oops, invalid $proj
    }
    
    // Or as ctype_alpha()
    if (!ctype_alpha($proj)) {
       // invalid $proj
    }
    
    // Method 2:  whitelist array
    // Array holds the valid possible values for $proj
    $valid_proj = array("project1", "barmitzvah", "wedding");
    if (!in_array($proj, $valid_proj)) {
      // Oops, invalid project
    }
    

    To get all the images from the filesystem, you can use readdir().

    // Use a glob to get all the images *.jpg
    $imgs = glob("/filesystem/path/to/images/portfolio/$proj/*.jpg");
    
    foreach ($imgs as $picture) {
      // Get only the base filename
      $picture = basename($picture);
    
      // Then build the <li>
      echo '<li><a href="javascript:void(0);"><img src="../images/portfolio/'.$proj.'/'.$picture;
      echo '</li>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a list of dynamic types that is actually of
I am trying to build some dynamic code that parses a text file with
I'm trying to set up my project to build several dynamic libraries that encompass
I'm trying to build a form that displays dynamic choices How do I build
I am trying to build a real-time web service that deals with dynamic 10k
I am trying to find the best way to build a dynamic linq query
I am trying to build a dynamic password recovery tool. You can specify a
I am trying to build a dynamic proxy for an interface with LinFu. The
I hope someone can help me..... i am trying to build a dynamic form
I am trying to Build a gallery in Android ( Not exactly what is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.