Hi again, thanks for the ideas, bernouli and bobthedog, but the problem is not that I can't get into the loop. In fact, in this particular instance it shouldn't enter the loop. The problem is that the function will not alter $result.
Here is my code snip...
$result;
function listings($table,&$result)
{
$query = "select count(*) from $table where customer_id='$check_id'";
if($query) echo "QUERY<br />"; //debug line
$execQuery = mysql_query($query);
if($execQuery) echo "EXECQUERY<br />"; //debug line
$result = mysql_result($execQuery, 0, 0);
if($result) echo "RESULT<br />"; //debug line
return $result;
}
$result = listings('accommodation',$result); //call function to see if listing exists
if ($result == 0)
{
echo "$result";
echo "<a href='add_accommodation.php'>Add an accommodation listing to the database.</a>";
echo "<br><br>";
}
Here is the output...
QUERY
EXECQUERY
0Add an accommodation listing to the database.
QUERY
EXECQUERY
Add a sightseeing listing to the database
Note that the debug lines confirm that both $query and $execQuery have been set, but it denies that $result exists! When the function returns, $result should == 1, but it == 0. This is because I have declared $result outside of the function and it is just using the default 0 value for an uninitialised variable. It is not using the return value from the function. The most peculiar thing is that if I set $result to explicitly == some other value inside the function ie. $result == 9, it returns the correct value!!!! It just doesn't like the line:
$result = mysql_result($execQuery, 0, 0);
although, if I use this code outside the function it works perfectly.
Thanks for your help, and I really hope someone can see what I'm doing wrong.
Cheers, Ben