Displaying all images in table using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
seaten
Forum Newbie
Posts: 22
Joined: Thu Mar 16, 2006 1:30 pm

Displaying all images in table using PHP

Post by seaten »

Hi guys,

This is giving me a lot of problems. I am able to insert in images in a table, and display ONE image. But I want to display all the images in the table, this is me giving trouble, this code at the moment is displaying the same image ten times.

As I am incrementing the $ID variable, I want different images to be displayed, but I just keep getting the same one. I do know it is working to some extent, when I put in this statement(echo $name I do get all the image names.


------------------------------
CODE

Code: Select all

<? 

$db = mysql_connect("xxxx", "xxxx","xxxx");

mysql_select_db("project140",$db); 

$id = 1;
while($id<10){
$query = "SELECT name, type, size, content FROM upload where id ='$id'"; 
$result = mysql_query($query) or die('Error, query failed'); 
list($name, $type, $size, $content) = mysql_fetch_array($result); 


if ($_REQUEST[gim] == $id) {


header("Content-length: $size"); 
header("Content-type: $type"); 


echo $content; 

exit; 
}






?> 

<html>
<title>Upload an image to a database</title><body>

<center><img src=?gim=<? echo $id ?> width=160 height=160><br>


</body>
</html>

<?
$id++;
}
?>
Burrito: Please use

Code: Select all

tags when posting code in the forums
removed host/un/pass[/size]
gchrome
Forum Newbie
Posts: 3
Joined: Thu Mar 16, 2006 2:27 pm

Post by gchrome »

Not exactly sure what you are trying to do, but this might work:

Code: Select all

<?php

if ($_REQUEST['gim']) {
  $db = mysql_connect("xxxx", "xxxx","xxxx");
  mysql_select_db("xxxx",$db); 
  $id = $_REQUEST['gim'];

  $query = "SELECT name, type, size, content FROM upload where id ='$id'"; 
  $result = mysql_query($query) or die('Error, query failed'); 
  $row = mysql_fetch_assoc($result);

  header("Content-type: " . $row['type']); 
  echo $row['content']); 
}
else {
?> 

<html>
<head>
<title>Upload an image to a database</title>
</head>
<body>
<center>

<?php
  for ($i=1;$i<10;$i++) {
?>
<p><img src=?gim=<?=$i;?> width=160 height=160></p>

<?php
  }
?>
</center>
</body>
</html>
<?php
}
?>
Post Reply