简体   繁体   中英

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.

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:

$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>";

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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