php - Empty MySQL database table cell triggers "Content" switch -


i'm having weird problem mysql database. make sure wasn't make dumb mistake, tested without database...

$content = 'hello world'; // $content = ''; switch ($content) {  case '':  echo 'no content 1';  break;  default:  echo 'content 1';  echo $content;  echo '<br><br>';  break; } 

it works. when content equals 'hello world' echoes "content 1." when set $content = '', echoes "no content 1."

but when delete first 2 lines , insert "hello world" in database, funny happens.

actually, works correctly @ first. when delete content database, still displays "content 1," though there's no database content. (it doesn't echo value $content.)

i checked database see if there might 0 (zero) in cell, there isn't. there isn't simple space.

on whim, added value 0 switch:

switch ($content) {  case '':  case 0:  echo 'no content i';  break;  default:  echo 'content i<br><br>';  echo $content;  break; } 

now opposite, display "no content" whether there's content in database or not.

am making simple mistake? upgraded mamp couple days ago, wondered if might kind of software bug.

on edit: googled more information , found solution...

if ($content != 0) {  echo "true";  echo $content; } else { echo "false"; echo $content; } 

however, doesn't work me, either; returns "false" there's content in database or not.

switch uses loose comparison, means non-empty strings interpreted 0 when comparing integer, unless initial portion of string converts non-zero number according rules in string conversion numbers.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -