Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > Problem with some codes
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 8th June 12:02
nico
External User
 
Posts: 1
Default Problem with some codes


Hello

Can you help me please..

Here's some PHP code :
// in a while process

$value="";

$reqt = mysql_query("select value from table where ref='$***'");

$value = mysql_result($reqt,0,"value");


$ok="0";

if ($value=="0"){

echo "$value";

$ok="1";

}

Normally only when value = 0 , ok = 1

but when i execute this script and when the sql doesn't return any fields

the ok=1 when value from sql = nothing (any fields returned)

i hope i'm clear
  Reply With Quote


  sponsored links


2 8th June 15:41
nico
External User
 
Posts: 1
Default Problem with some codes


nobody can help me?

"Nico" <nico-bc@belcenter.com> a écrit dans le message de news:
45228ce7$1@ns2.belcenter.be...
  Reply With Quote
3 8th June 15:41
mootmail-googlegroups
External User
 
Posts: 1
Default Problem with some codes


This is happening because "0", is equivalent to FALSE and, I believe,
NULL, in PHP.
When your query returns no values, it is returning a value equivalent
to a 0.

There are two ways to try getting around this. The first, I'm not
certain will work, but you can try anyway.
- use '===' instead of '==' in your if statement. '===' tests for
equality and that the compared values are of the same type.
- check the number of rows returned with mysql_num_rows, then only echo
the variable if >0
  Reply With Quote
4 8th June 15:41
nico
External User
 
Posts: 1
Default Problem with some codes


i've found a workaround:
i used
if ($value != "" and $value=="0"){
}

works
because when sql doesn't return any values
$values = "" :-)

<mootmail-googlegroups@yahoo.com> a écrit dans le message de news:
1159993017.064199.264780@e3g2000cwe.googlegroups.c om...
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666