php - Store multiple rows from mysql database into one single variable -


this hard me, i'm trying store multiple rows table in mysql single variable


$mysql_statementjc = "select * `dog`.`cat` `name` = '$name'"; $mysql_commandjc = mysql_query($mysql_statementjc);    while($row = mysql_fetch_array($mysql_commandjc)){      $followi = $row['industry'];      $groupconcat = $followi . " or ";      echo $groupconcat; } 

this appproach, @ end of can "sam, john, bob" saved $groupconcat can used elsewhere.

many thanks.

each time through loop, add desired value array. then, after loop, use implode() function create desired output.

while($row = mysql_fetch_array($mysql_commandjc)){      $followi = $row['industry'];      $resultarray[] = $followi; }  $groupconcat = implode(" or ", $resultarray);  echo $groupconcat; 

note should stop using mysql library , instead use mysqli or pdo.


Comments

Popular posts from this blog

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -