first lets run this test:
frist thing, lets change your mysql_fetch_array to mysql_fetch_assoc, or use the MYSQL_ASSOC flag on mysql_fetch_array;
The reason being is mysql_fetch_array returns both associative and numeric values for indexes in the array, so when you
while($row=mysql_fetch_array($query))
$row will actually look like this
$row[0] = 1
$row['id']=1
$row['1']='tommy'
$row['name']='tommy'
so it could be filling list($id,$name) with 1 and 1 because it's returning the first 2 indexes of the array. So lets iterate through the array and see what we're actually getting back from the db
<?PHP
$query = "SELECT id, name FROM photo";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while($row = mysql_fetch_assoc($result)){
echo "<pre>";
print_r($row);
echo "</pre>";
?>
<a href="down.php?id =<?php echo $row['id']; ?>"><?php echo $row['name'; ?></a> <br>//parser error in this line
<?php
}
}
?>
this should print out all the values of $row you are retrieing before you links, if that works then just remove the pre and print statements
moving onto your second quesiton
<a href="down.php?id =<?php $ro=$id; ?>"><?php echo $name; ?></a>
Here you are simply setting $ro to $id, so it wont print $id in the link
<?
}
?>
this all happends outside your while loop, so the value if $_SESSION['id'] will be the last value that $ro was given, which will be the last value of $id in the while loop.
If you want to pass a session variable containing all the id numbers to the next page, then your session variable must also be an array
echo $ro;
$_SESSION['id']=$ro;
so $_SESION['id']=$ro; would have to become
$_SESSION['id'][]=$ro; this would create a session variable 'id' with multiple id values, if you need a easier way to sort your array, i suggest making the array order like how ever you would use it.
<?PHP
SESSION_WRITE_CLOSE();
$i++;
}
down to your down.php
i take it you are trying to force a image file download?
if so, you have to read the image or header location to it rather then echo the link in the body. Let me know what $content contain, unless it contains the actual image content code in the database, this code wont work
<?php
SESSION_START();
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("modile") or die(mysql_error());
if(isset($_SESSION['id']))
{
$id = $_SESSION['id'];
$query = "SELECT name, type, size, content " .
"FROM photo WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
change your echo $content
if $content is a url to the image, then you can:
readfile($content);
exit;
}
?>