为while循环结果创建一个变量

|
while ($topic = mysql_fetch_assoc ($result)); {
   echo \"{$topic[\"overtag \"]} \";
}
我的while循环的结果显示如下: 苹果橙色香蕉 我希望能够获取所有这些结果并将其放入变量中,并使它看起来像这样: $水果=苹果橙香蕉 我将如何做到这一点?     
已邀请:
        隐含运算符。=
$fruits = \'\';
while ($topic = mysql_fetch_assoc ($result)); {
    $fruits .= \"{$topic[\"overtag \"]} \";
}
    
        
// I love arrays.
$fruits = array();
while ($topic = mysql_fetch_assoc ($result)); {
   $fruits[] = (string)$topic[\"overtag \"];
}

// If you don\'t want an array, but a string instead, use implode:

$fruits = implode(\' \', $fruits)
    
        您只需要将每个连接到循环内的变量上
$fruits = \"\";
while ($topic = mysql_fetch_assoc ($result)); {
  echo \"{$topic[\"overtag \"]} \";
  $fruits .= $topic[\'overtag\'] . \" \";
}
// This is going to result in an extra space at the end, so:
$fruits = trim($fruits);
哦,还有,您有一个错误的分号,它将中断您的while循环:
while ($topic = mysql_fetch_assoc ($result)); {
                                   --------^^^--
应该:
while ($topic = mysql_fetch_assoc ($result)) {
    
        使用下面的PHP代码,您可以从数据库表中获取数据并显示在网页上:
    $sql_query=\"select * from yourTable\";   
    $result=mysqli_query($connection,$sql_query); 
    if(mysqli_num_rows($result) > 0)
    { 
      while($row = $result->fetch_array(MYSQLI_ASSOC))
      { 
        echo \"ID \".$row[0];//echo \"ID \".$row[\"ID\"];
        echo \"Name \".$row[1];//echo \"Name \".$row[\"Name\"];
       }
    }
    else
    {
      echo \"No Record\";
    }
    

要回复问题请先登录注册