php - How do I display multiple image filenames from MySQL on page -


i'm working on small php program stores/retrieves information mysql db , have hit roadblock in displaying images. can single image display , can see images returned in array don't know go there. background info:

my db schema pretty simple table i'm using images named img_data , contains following:

  • id (primary)
  • serialnum (holds serial of item image belongs to)
  • file_name
  • file_size
  • file_type

please take @ following related snippet of code:

     <?php  $file_path = "http://localhost/test/image_uploads/$serial/";  $sql= "select img_data.file_name img_data serialnum=:serial";  $query = $db->prepare( $sql );  $query->bindparam(':serial', $serial, pdo::param_str);  $query->execute();   $results = $query->fetchall();   ?>    <?php foreach( $results $row )     $gimmenewval = str_replace(' ', '%20',$row['file_name']);   $src=$file_path.$gimmenewval;    $gimmeurl = "<img src=".$src.">";    echo $gimmeurl;    ?> 

this code pulls filename each image belonging serial entered search form, turns proper url , displays pic on page 1st result. i'd not 1 image, images returned query. how approach problem?

now following edited fixed , working code using suggestions @paul though used rawurlencode() on urlencode().

 <?php  $file_path = "http://localhost/test/image_uploads/$serial/";  $sql= "select img_data.file_name img_data serialnum=:serial";  $query = $db->prepare( $sql );  $query->bindparam(':serial', $serial, pdo::param_str);  $query->execute();   $results = $query->fetchall();   ?>    <?php foreach( $results $row ){     $gimmenewval = rawurlencode($row['file_name']);   $src=$file_path.$gimmenewval;    $gimmeurl = "<img src=".$src.">";    echo $gimmeurl;}    ?> 


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -