简体   繁体   English

从 SQL 中选择语句到 PHP 数组中

[英]select statement from SQL into PHP array

The following PHP code, I tried to retrieve some values from the table by "word" column which happy, like, free and help are in this column.以下 PHP 代码,我尝试通过“word”列从表中检索一些值,这些值在此列中包含快乐、喜欢、免费和帮助

while($row=mysqli_fetch_array($result_kwp,MYSQLI_ASSOC))
        {
            $v_kw = $row["word"]." ";
            echo $v_kw;
        }
$category_text = array(
'positive' => $v_kw,
);
 echo "<b>positive</b> Category: ". $category_text['positive']."<br/>";

my output:我的输出:

happy like free help 
positive Category: help 

my question is why $category_text['positive'] is contained only help word?我的问题是为什么 $category_text['positive'] 只包含帮助词? How can I put every word in this array?我怎样才能把每个单词都放在这个数组中?

In your code, every iteration reassigns $v_kw to the new $row["word"] .在您的代码中,每次迭代都会将$v_kw重新分配给新的$row["word"] You have to concatenate all your results by using .=您必须使用.=连接所有结果

$v_kw = "";
while($row=mysqli_fetch_array($result_kwp,MYSQLI_ASSOC))
        {
            $v_kw .= $row["word"]." ";
            echo $row["word"];
        }
$category_text = array(
'positive' => $v_kw,
);
 echo "<b>positive</b> Category: ". $category_text['positive']."<br/>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM