Hi there,
I am having a small problem with a script I'm writing. I am generating a list of links dynamically from a database whereby when they are clicked they pass a 'picid' that matches to a corresponding 'homeid' and displays the photo for that link (picture of the house).
The problem arises when the possibility of NO 'homeid' matches the passed 'picid'. This is what I have...
Code:
DbConnect();
global $picid;
if($picid)
{
$result = @mysql_query("SELECT * FROM pictures where picid = homeid");
if(!$result)
{
echo("ERROR: " . mysql_error() . "\n$sql\n");
exit();
}
while($myrow = mysql_fetch_array($result))
{
if(($picid == $myrow["homeid"]) && (!$myrow["url"]))
{
echo "<center>Sorry, no additional photos available for this home</center>";
}
if($picid == $myrow["homeid"])
{
echo "<center><table border=1>\n";
echo "<tr><td>$myrow[url]</td></tr></table></center>";
}
}
}
else
{
echo "No ID passed";
}
If I put in a conditional like this in the while statement...
Code:
if($picid != $myrow["homeid"])
{
echo "Error";
}
it will almost always come back true because it will most likely loop through several times before it finds the right 'homeid', and as a result, print out "Error" numerous times.
I was populating a variable with a certain value if the condition was true, loading the results in an array, and just printing out the first element of the array to prevent it from printing out multiple times, but even if 'picid' matches 'homeid', it will most likely loop through at least once before finding it which results in the printing of the error message.
Any ideas how I can prevent the message from being displayed when there is actually a match even though ($picid != $myrow["homeid"]) will come back true 99.9% of the time in the loop?
Thanks for any help