Skip navigation
Currently Being Moderated

Output all Image URLs from MySQL using  PHP

Jul 29, 2012 1:08 PM

I am trying to display all image urls for products in a Mysql table under the columun name 'Photolocation'.  Each row can have up to  16 pictures per item seperated by commas.  They now cut off at the first photo. 

How do I make the code display them all as images?





Photolocation <---  MySql Column Location:,http ://,ht tp://, g, jpg, 5.jpg, S-6.jpg

---------------------------------------------------------------------- ----------------------------------------------------------------


Php Code:


<?php require_once('Connections/Practice.php'); ?>


if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")


  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;




  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);



  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";


    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";


    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";


    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";


    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;



  return $theValue;





mysql_select_db($database_Practice, $Practice);

$query_photo = "SELECT Photolocation FROM fayettevillemaster";

$photo = mysql_query($query_photo, $Practice) or die(mysql_error());

$row_photo = mysql_fetch_assoc($photo);

$totalRows_photo = mysql_num_rows($photo);


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">



<meta http-equiv="Con=96+-ptent-Type" content="text/html; charset=utf-8">

<title>Untitled Document</title>









<img name="" src="<?php echo $row_photo['Photolocation']; ?>" width="350" height="350" alt="">








  • Currently Being Moderated
    Jul 29, 2012 2:18 PM   in reply to mercer1022

    >Each row can have up to  16 pictures per item seperated by commas.


    That's a poor database design decision. Each row should only contain one url. Use another table to store multiple rows of image location data for each item.


    As an alternative, you could probably achieve what you want using the PHP explode function, but you would need to code that by hand. But I would suggest fixing the database design instead.

    Mark as:
  • Currently Being Moderated
    Jul 29, 2012 9:13 PM   in reply to mercer1022

    I am assuming that the list of URLs shown is only a partial and there are many more in multiple cells in the spreadsheet.  One possible way to convert from SS is to copy the SS cells containing the URLs to a word processor (it should come into the WP as a table), convert the table to text, using a 'replace all', change the .jpg, (.jpg<comma>) with .jpg<paragraph mark>; this will result in a column of URLs.  Copy (or import) the column of URLs into a table in your DB.  Don't forget you'll need a field in this database linking each URL to it's corresponding record in the main table.




    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points