$result = mysql_query("select * from bivalues WHERE myvalue - '$zchar'); if (mysql_num_rows($result) { echo "Result 2 - found it"; } else { echo "Not found"; }
This leaves you with the option to start processing the data as soon as error checking is over. Using Count, you'll have to re-retrieve the data from the database, which takes twice as long time as doing it only once.. (or thereabout).
The problem you had is that no matter if the query presents results or not, the result variable is only set to 0 (thus the !$result syntax gives results) when there's been an error in the mysql query. Simply an empty table will not return an error!
Mike
On Apr 15, 2004, at 16:54, pete M wrote:
the way I would do this is with count()
$row = mysql_fetch_assoc("SELECT count(*) as c FROM bivalues WHERE myvalue = '$zchar'")
if ($row['c'] > 0) { echo 'result 2 - found it' }else{ echo 'NOT found' } hope it helps
Pete
Douglas D Hull wrote:
I am trying to find data, or if not found set a variable to "Err". myvalue being a variable in my database and $zchar being my value to find.
The following result is never 1 even if no values were found, so the result is always 2. If the finding value does exist in my database this does find the correct value:
if (!$result = mysql_query("SELECT * FROM bivalues WHERE myvalue = '$zchar'"))
{
echo 'result 1 - not found';
$myresut = "Err";
}
else
{
{echo 'result 2 - found it'
}
The following result is never 2 even if the value actually exist in my database, so the result is always 1:
if (!$result = mysql_query("SELECT * FROM bivalues WHERE myvalue = $zchar"))
{
echo 'result 1 - not found';
$myresult = "Err";
}
else
{
{echo 'result 2 - found it'
}
Thanks for any help,
Doug
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php