Solved

displaying more than one image from database php

Posted on 2011-03-09
4
198 Views
Last Modified: 2012-05-11
Hi,

i have a slideshow that i am altering to be able to use with php file upload, below is the page that displays the images.  i can only get it to display one image at a time, well multiple instances of the same image.  How can i make it show all the images (and related info) from the database, the number of images in the database might change sometimes only 6 others 16.

thanks,

Mskazza
<?php require_once('Connections/imageflow.php'); ?>
<?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";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_imageflow, $imageflow);
$query_images = "SELECT * FROM images ORDER BY `path` ASC";
$images = mysql_query($query_images, $imageflow) or die(mysql_error());
$row_images = mysql_fetch_assoc($images);
$totalRows_images = mysql_num_rows($images);
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>ImageFlow</title>
		<meta name="robots" content="index, follow, noarchive" />
		<link rel="stylesheet" href="style.css" type="text/css" />

		<!-- This includes the ImageFlow CSS and JavaScript -->
		<link rel="stylesheet" href="imageflow.css" type="text/css" />
		<script type="text/javascript" src="imageflow.js"></script>

	</head>
	<body>
		<h1>ImageFlow</h1>

		<!-- This is all the XHTML ImageFlow needs -->
		<div id="myImageFlow" class="imageflow">
			<img src="img/<?php echo $row_images['path']; ?>" longdesc="<?php echo $row_images['desc']; ?>" alt="Image 1" />
			<img src="img/<?php echo $row_images['path']; ?>" longdesc="img/img2.gif" alt="Image 2" />
			<img src="img/<?php echo $row_images['path']; ?>" longdesc="img/img3.gif" alt="Image 3" />
			<img src="img/img1.gif" longdesc="img/img1.gif" width="400" height="300" alt="Image 4" />
			<img src="img/img2.gif" longdesc="img/img2.gif" width="300" height="400" alt="Image 5" />
			<img src="img/img1.gif" longdesc="img/img1.gif" width="400" height="300" alt="Image 6" />
			<img src="img/img2.gif" longdesc="img/img2.gif" width="300" height="400" alt="Image 7" />
			<img src="img/img3.gif" longdesc="img/img3.gif" width="400" height="400" alt="Image 8" />
			<img src="img/img1.gif" longdesc="img/img1.gif" width="400" height="300" alt="Image 9" />
			<img src="img/img1.gif" longdesc="img/img1.gif" width="400" height="300" alt="Image 10" />
			<img src="img/img2.gif" longdesc="img/img2.gif" width="300" height="400" alt="Image 11" />
			<img src="img/img3.gif" longdesc="img/img3.gif" width="400" height="400" alt="Image 12" />
			<img src="img/img2.gif" longdesc="img/img2.gif" width="300" height="400" alt="Image 13" />
			<img src="img/img3.gif" longdesc="img/img3.gif" width="400" height="400" alt="Image 14" />
			<img src="img/img3.gif" longdesc="img/img3.gif" width="400" height="400" alt="Image 15" />
		</div>

	</body>
</html>
<?php
mysql_free_result($images);
?>

Open in new window

0
Comment
Question by:Karen Liddy
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35085331
Use a loop
<div id="myImageFlow" class="imageflow">
<?php
while($row_images = mysql_fetch_assoc($images)){
?>

<img src="img/<?php echo $row_images['path']; ?>" longdesc="<?php echo $row_images['desc']; ?>" alt="Image 1" />

<?php
}
?>

Open in new window

0
 

Author Comment

by:Karen Liddy
ID: 35086805
thanks for your reply.

the above is not returning anything, i must be doing something wrong, please find my code below.  it just gets stuck saying loading images, but nothing ever loads.

 
<?php require_once('Connections/imageflow.php'); ?>
<?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";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_imageflow, $imageflow);
$query_images = "SELECT * FROM images ORDER BY `path` ASC";
$images = mysql_query($query_images, $imageflow) or die(mysql_error());
$row_images = mysql_fetch_assoc($images);
$totalRows_images = mysql_num_rows($images);
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>ImageFlow</title>
		<meta name="robots" content="index, follow, noarchive" />
		<link rel="stylesheet" href="style.css" type="text/css" />

		<!-- This includes the ImageFlow CSS and JavaScript -->
		<link rel="stylesheet" href="imageflow.css" type="text/css" />
		<script type="text/javascript" src="imageflow.js"></script>

	</head>
	<body>
		<h1>ImageFlow</h1>

		<!-- This is all the XHTML ImageFlow needs -->
		<div id="myImageFlow" class="imageflow">
			<?php
while($row_images = mysql_fetch_assoc($images)){
?>

<img src="img/<?php echo $row_images['path']; ?>" longdesc="<?php echo $row_images['desc']; ?>" alt="Image 1" />

<?php
}
?>
		</div>

	</body>
</html>
<?php
mysql_free_result($images);
?>

Open in new window


the only thing visible in the brower is :

 
<!DOCTYPE html>

<html lang="en">

	<head>

		<meta charset="utf-8" />

		<title>ImageFlow</title>

		<meta name="robots" content="index, follow, noarchive" />

		<link rel="stylesheet" href="style.css" type="text/css" />



		<!-- This includes the ImageFlow CSS and JavaScript -->

		<link rel="stylesheet" href="imageflow.css" type="text/css" />

		<script type="text/javascript" src="imageflow.js"></script>



	</head>

	<body>

		<h1>ImageFlow</h1>



		<!-- This is all the XHTML ImageFlow needs -->

		<div id="myImageFlow" class="imageflow">

					</div>



	</body>

</html>

Open in new window

0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 250 total points
ID: 35086924
Remove line 37
$row_images = mysql_fetch_assoc($images);
Does the query
SELECT * FROM images ORDER BY `path` ASC
run directly on the database return images rows ?
0
 

Author Closing Comment

by:Karen Liddy
ID: 35087031
Thanks very much for the speedy reply. brilliant :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now