Hi PHPers,

Firstly, a Very Happy New Year To ALL!!

Hope everybody enjoyed this festive season :cheesy:

Back to work, sigh...

I am encountering this problem, below is a code which i have written, but the page only displayed the result of my code which is line 27. But when want to retrieved the image from my database on line 33, nothing happens..may i knoe what is wrong with my code??

thanks and appreciates for any advice,
tristan

<?
// database connection
$host = "localhost";
$user = " ";
$pass = " ";
$db = "imagedb";
$usertable= "userrgbvalues3020";
$imagetable="imagergbvalues3020";

$conn = mysql_connect($host, $user, $pass)
OR DIE (mysql_error());
@mysql_select_db ($db, $conn) OR DIE (mysql_error());

//sql statement to select similar images

$sql_retrievename="SELECT distinct $imagetable.image_name FROM $imagetable,$usertable WHERE $imagetable.position = $usertable.position AND $imagetable.red =

$usertable.red AND $imagetable.green = $usertable.green AND $imagetable.blue = $usertable.blue AND $imagetable.red !=0 AND $usertable.red !=0 AND

$imagetable.green !=0 AND $usertable.green !=0 AND $imagetable.blue !=0 AND $usertable.blue !=0" ;

$sql_queryname=mysql_query($sql_retrievename) or die(mysql_error());
$numrows_name=mysql_num_rows($sql_queryname);

for($i=0;$i<$numrows_name;$i++){
$row_name = @mysql_fetch_array($sql_queryname);
$retrieved_name = $row_name["image_name"];
print $retrieved_name ; // line 27
echo "\n";
}

//sql statements to retrieve image

$sql_retrieveimage="SELECT * FROM image WHERE image_name= '$retrieved_name' "; // line33
$sql_queryimage=mysql_query($sql_retrieveimage) or die(mysql_error());
$numrows_image=mysql_num_rows($sql_queryimage);

for($j=0;$j<numrows_image;$j++){
$row_image = @mysql_fetch_array($sql_queryimage);
$retrieved_image = $row_image["image"];
print $retrieved_image;
echo "\n";
}

?>

replace this:

$sql_queryname=mysql_query($sql_retrievename) or die(mysql_error());
$numrows_name=mysql_num_rows($sql_queryname);

for($i=0;$i<$numrows_name;$i++){
$row_name = @mysql_fetch_array($sql_queryname);
$retrieved_name = $row_name["image_name"];
print $retrieved_name ; // line 27
echo "\n";
}

for this... it is simple

$sql_queryname=mysql_query($sql_retrievename) or die(mysql_error());

while ($data=mysql_fetch_object($sql_queryname)) {

print $data->image_name;
echo "\n";
}
This article has been dead for over six months. Start a new discussion instead.