![]() | |
#11
| |||
| |||
|
|
I just cannot believe that if ($string) does not give the same result as if ($string != 0) |
#12
| |||
| |||
|
|
Hi, Can someone tell me why this little piece of php/mysql code fails? $row = $result->fetch_assoc(); if ($clog) fwrite($logfile,"row['nametag'] {$row['nametag']}\n"); if ($row['nametag'] != 0) { if ($clog) fwrite($logfile,"name {$row['nametag']}\n"); } I've got this logfile where I am putting debug output. In the above, the first fwrite works -- it writes the name contained in the row value 'nametag'. But then, when I test that same value for nonzero, it fails? If never prints that second line. Why should $row['nametag'] fail the != 0 test? Thanks Bob |
#13
| ||||
| ||||
|
|
Simple. You're trying to check to see if a string value is a numeric zero or not. That ain't gonna happen. For instance if ($a)=1 do this. |
|
What you need to do is to test for NULL. |
|
That is, the string has no content. BASIC would use something like if a$<>"" then dothis. |
|
If my line wrap is screwed up, that's because I hit some keys I should not have. |
#14
| |||
| |||
|
|
if ($a)=1 do this. 'This' will be done, because now, you assign value 1 to $a successfully. Nope. That is syntax error. Parentheses make this a value, not a variable. |
#15
| |||
| |||
|
|
On 27.09.2011 09:21, Erick T. Barkhuis wrote: if ($a)=1 do this. 'This' will be done, because now, you assign value 1 to $a successfully. Nope. That is syntax error. Parentheses make this a value, not a variable. |
![]() |
| Thread Tools | |
| Display Modes | |
| |