Store multiple rows from mysql database into one single variable

后端 未结 3 1888
盖世英雄少女心
盖世英雄少女心 2021-01-24 12:23

this is really hard for me, i\'m trying to store multiple rows from my table in mysql into a single variable


$mysql_statementJc = \"SELECT * FROM `dog`.`ca         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-24 13:16

    you want to create a concatenated string, php has the .= syntax for this:

    $groupConcat='';
    
     while($row = mysql_fetch_array($mysql_commandJc)){
        $groupConcat .= $row['industry'] . " OR ";
    }
        echo $groupConcat; //no point echoing inside the loop
    

    sometimes a better approach is to use an array and implode()

    $groupConcat=array();
    
     while($row = mysql_fetch_array($mysql_commandJc)){
        $groupConcat[] = $row['industry'];
    }
        echo implode(' OR ',$groupConcat);
    

提交回复
热议问题