简体   繁体   中英

Separate each piece of data from sql table through PHP

I Have a string of data in my SQL table: Renovated, New, Downtown. I would like to display each piece of data into a list through PHP is this possible?

Here is what I have right now:

 <details>
  <summary>Listing Features</summary>
 <ul>
  <li><?php echo $page['tags']; ?></li>
 </ul>
</details>

Right now all the data is displayed on one 'li' and not individually. Thanks,

If the tags in $page['tags'] is delineated by commas, you should split the string by the separator first, then loop over the items rendering a tag per iteration.

<details>
  <summary>Listing Features</summary>
 <ul>
  <?php foreach(explode(",", $page['tags']) as $tag) { ?>
    <li><?php echo $tag; ?></li>
  <?php } ?>
 </ul>
</details>

If you have a string that contains comma separated values, you could use explode

$values=explode(',',$str);

And then loop through this array, and echo a list item for each

foreach($values as $v){
    echo "<li>$v</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