0

I feel a bit stupid having to ask this, but for the life of me it won't work and I know I must be missing something small. I have the following PHP code for a gallery of model's photos. I have 2 pages. guests1.php and guests2.php. Guests1 shows the thumbnails and lists all the models. guests2 will show a particular model's individual portfolio. I am trying to pass the model name in the url, as I need it for the title on the second page and also for the directory name, so that the page knows where to find the pictures.

Simple enough, I thought, just add it into the url as a variable. No problem... however no matter how I write it, it will not put it in the url. The name of the model is always missing... however if I echo the variable it does it no problem?! The pages are working wonderfully apart from this one little thing and it's driving me bonkers. Any help most appreciated.

Here is the code :

    <?php
  echo "<div class=\"guests-gallery\">"; 
  echo "<ul class=\"guests-gallery-list\">";

$dirs = glob("guests/*", GLOB_ONLYDIR);
   foreach($dirs as $model) {

 $files = glob($model. "/*.{jpg,png,gif,JPG}", GLOB_BRACE);
 foreach($files as $file) {
 $m = basename($model);
  echo "<li><a href=\"index.php?page=guests2&amp;model=\"" .$m. "\">";
  echo "<img src=\"" . $file . "\" alt=\"" .basename($model). "\"></a><br />
 <h3>" .basename($model). "</h3></li>";
 }
}
echo "</ul></div>";

 ?>

2 Answers 2

1

You're making your code harder to read by double quoting and escaping your HTML quotes so you're not spotting your mistake with the quotes, make it easier to read and write by using single quotes on your echos leaving the double quotes for the html then you won't need to escape them and it'll be easier to spot the extra unnecessary " you included.

Try this:

<?php
    echo '<div class="guests-gallery">'; 
    echo '<ul class="guests-gallery-list">';

    $dirs = glob("guests/*", GLOB_ONLYDIR);
    foreach($dirs as $model) {
        $files = glob($model. "/*.{jpg,png,gif,JPG}", GLOB_BRACE);
        foreach($files as $file) {
            $m = basename($model);
            echo '<li><a href="index.php?page=guests2&model=' .$m. '">';
            echo '<img src="' . $file . '" alt="' .basename($model). '"></a><br>
            <h3>' .basename($model). '</h3></li>';
        }
    }
echo '</ul></div>';
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks Andrew! That worked. I've started rewriting all the quotes too. :)
0

try removing the quote s from the model and maybe try using the & character without using it encoded:

echo "<li><a href=\"index.php?page=guests2&model=" .$m. "\”>something</a></li>";

Tell me if this works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.