简体   繁体   English

如何将while循环的所有结果作为字符串输出?

[英]How can I output all results of a while loop as a string?

I am wanting to pull data from MySQL and create a string with all the data pulled in a string as 1 variable. 我想从MySQL中提取数据并创建一个字符串,其中所有数据都以字符串形式拉入1变量。

while($row = mysqli_fetch_array($res))
{

$x= $row['SessionValue'];

}

I know that this is miles away from what I am after but if the data pulled is: a,b,c,d (commas representing each loop) my desired output would be: 我知道这距离我所追求的还有几英里,但是如果拉出的数据是:a,b,c,d(表示每个循环的逗号),我想要的输出将是:

$x='<li>a</li><li>b</li><li>c</li><li>d</li>'

How would I do this? 我该怎么做?

Just chain it in a variable 只需将其链接在变量中即可

while($row = mysqli_fetch_array($res))
{

     $x= $x."<li>".$row['SessionValue']."</li>";

}

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

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