Get comma-separated values from the database and organize them in li

-1

I have in my database, in my table "db_home_content" the column "a2_content_x_imploders" ("x" would be its content number, as represented in the image) that contains some data separated by commas. Example: Site em HTML5, Alta velocidade, Responsivo .

I need to get this data and organize it according to the quantity in <li> 's as shown in the image. Is there a function in PHP or MySQL that does the opposite of implode? If yes, how does it work for my case?

    
asked by anonymous 27.01.2017 / 14:26

3 answers

3

Yes! Function explode() .

Example:

$lista = "item1,item2,item3";
$lista = explode(",", $lista);
// Aqui lista passou a ser um array("item1", "item2", "item3");

To write the LIs, just use foreach ().

Example:

$htmlLista = "ul";
foreach ($lista as $item) {
   $htmlLista .= "li".$item."li";
}
$htmlLista .= "ul";
echo $htmlLista;
// Lembre-se de adicionar < e > nas tags, não consigo adicionar na resposta pois estes caracteres são removidos.
    
27.01.2017 / 14:31
1

With Javascript, you can separate the text by comma, and add the li :

var texto = 'Site em HTML5, Alta velocidade, Responsivo'.split(',');
texto.forEach(function(item) {
  var li = document.createElement("li");
  li.innerHTML = item;
  document.getElementById("siteFit").appendChild(li);
});
li {
  list-style-type: none;
}
<h3>Site Fit</h3>
<ul id="siteFit"></ul>
    
27.01.2017 / 14:31
0
$conteudo = 'Site em HTML5, Alta velocidade, Responsivo';

$conteudoArray = explode(',', $conteudo);

echo '<ul>';
foreach($conteudoArray as $conteudo) {
    echo'<li>' . $conteudo . '</li>';
}
echo '</ul>';
    
27.01.2017 / 14:36