Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Saturday, January 23, 2016

while returing values in single line

while returing values in single line


I am using ajax and returning values by the following method

$query = mysql_query("SELECT DISTINCT * FROM symptom WHERE symptom LIKE '%$key%'")or die('couldnt select');  while(($row = mysql_fetch_array($query))!=false){        echo $row['disease'];    }     

but the result received in ajax function shows the result like

streppneumonia  

instead of

strep  pneumonia  

What am i doing wrong?I just can't figure out the problem here.

Answer by Prisoner for while returing values in single line


Quick fix: echo $row['disease'].'
';

Although really your your web service should return data in a better format like JSON, and from there you should use javascript to break the data up.

Answer by X.L.Ant for while returing values in single line


Try

echo $row['disease'].'
';

Answer by som for while returing values in single line


$query = mysql_query("SELECT DISTINCT * FROM symptom WHERE symptom LIKE '%$key%'")or die('couldnt select');  $str = '';  while(($row = mysql_fetch_array($query))!=false){        $str .= $row['disease']. "
"; } echo $str;

Answer by Angelin Nadar for while returing values in single line


when using ajax and returning multiple values, send it in the json format. You cannot distinguish the multiple values although you can break with break tag on the client side:

  

Later, decode by js on the client side

Answer by NullPoi?te? for while returing values in single line


try

while(($row = mysql_fetch_array($query))){        echo $row['disease'].'
'; }

Note

mysql_* function are deprecated please use PDO or MySQLi


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.