0

Hi this is my piece of code , I don't understand why the code within my foreach is not reachable ,

$content = "";
/*** the upload directory ***/
$upload_dir= '/gallery/school/'.$name.'/';

$images = glob($upload_dir."*.*");
foreach($images as $image) {

    $content .= '   <li>
       <img src="'.$image.'" alt="">
       <p class="caption">This is a caption</p>
       </li>';
} 

Here is the Entire code , the code before the foreach works perfectly fine . But the code inside is unreachable when i try to echo the $content , It gives blank output i.e $content does not contain anything

<?php

include "storescrpt/connect_to_sql.php";

if(isset($_GET['dc_id']))
{
    $day_care =     $_GET['dc_id'];
    $sql = mysql_query("select * from school where id='$day_care'");
    $count =mysql_num_rows($sql);
    if($count>0)
    {    
        while($row= mysql_fetch_array($sql))
        {  
            $name = $row['name'];
            $phone = $row['phone'];
            $address = $row['address'];
            $desc = $row['desc'];
            $Fac = $row['Fac'];
            $area = $row['area'];
            $gog = $row['gog'];     
        }
    }

    $content = "";
    /*** the upload directory ***/
    $upload_dir= '/gallery/school/'.$name.'/';

    $images = glob($upload_dir."*.*");
    foreach($images as $image) {
        echo $image;
        $content .= '   <li>
            <img src="'.$image.'" alt="">
            <p class="caption">This is a caption</p>
            </li>';
    }
}

?>
kuldeep.kamboj
  • 2,566
  • 3
  • 26
  • 63
CleanX
  • 1,158
  • 3
  • 17
  • 25
  • Did you [enable error reporting](http://stackoverflow.com/a/6575502/1438393)? – Amal Murali May 26 '14 at 12:07
  • what does a var_dump($images) give you? – Daan May 26 '14 at 12:08
  • 5
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. – Kermit May 26 '14 at 12:09
  • mysql is deprecated, take a look in PDO, is very secure. –  May 26 '14 at 12:17
  • Hey I got the solution , It was a stupid mistake , I actually had to give $upload_dir= 'gallery/school/'.$name.'/'; instead of $upload_dir= '/gallery/school/'.$name.'/'; difference is '/' before gallery/school/'.$name.'/'; – CleanX May 26 '14 at 12:23

0 Answers0