Helpful Information
 
 
Category: PHP Development
if $result is empty rror appeared ?

$sqltext= "select userno from qquote where quoteno=$quoteno ";
$result = mysql_query($sqltext);
$a = mysql_fetch_row($result);
echo "a : " . $a . "<br>";

if $result is blank, the following appeared :-

Warning: 0 is not a MySQL result index in ./common.inc on line 246
a :


how do i check that $result is empty and then return a value ?

thanks

No, if $result==0 you get the warning.

a result of 0 on a mysql query means that the mysql server returned an error. It does not mean an empty set.

However if you wanted to check to see if it result was empty anyways, you can do this:

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<?
$sqltext= "select userno from qquote where quoteno=$quoteno ";
$result = mysql_query($sqltext);
if(mysql_num_rows($result)>0){
$a = mysql_fetch_row($result);
echo "a : " . $a . "<br>";
}else{
echo "empty query";
}
?>
[/quote]

$sqltext= "select userno from qquote where quoteno=$quoteno ";
$result = mysql_query($sqltext);
$a = mysql_fetch_row($result);
echo "a : " . $a . "<br>";


Your problem is with your echo line. You are trying to output $a, but $a is an array after fetching the row. You should use $a["userno"]. $a becomes an array because your row may have more than one column.

Josh

$sqltext= "select userno from qquote where quoteno=$quoteno ";
$result = mysql_query($sqltext);
$a = mysql_fetch_row($result);
echo "a : " . $a . "<br>";

if $result is blank, the following appeared :-

Warning: 0 is not a MySQL result index in ./common.inc on line 246
a :


how do i check that $result is empty and then return a value ?

thanks

use mysql_num_rows($result) to get number of rows returned

Regards,
Ranjan










privacy (GDPR)