I'm creating a website and would like to know how I can use tags with MySQL and PHP.
I have two tables: produtos
and informacao
.
In the informacao
table I have a field called related products where I will put products separated by commas, how can I then get those names without the commas so I can do a search with each of them?
I have the following code:
<?
$explode = explode(',',$relacionados);
foreach($explode as $nome){
$result = $connection -> query("select * from produtos where titulo='$nome' and linguagem='$lang'");
while($row = $result -> fetch_array(MYSQLI_ASSOC)){
$id = $row['id'];
$titulo = $row['titulo'];
$resumo = $row['resumo'];
$imagem = $row['imagem'];
$categoria = $row['tags'];
?>
<div class="grid_3">
<div class="box2 wrap1 wow fadeInLeft" data-wow-delay="0.1s">
<a href="verproduto.php?id=<?=$id?>&lang=<?=$lang?>" id="produto"><img class="first" src="<?=$imagem?>" alt=""/></a>
<div class="caption bggreen equal">
<h6 class="text_3 colorblue">
<a href="verproduto.php?id=<?=$id?>&lang=<?=$lang?>"><?=$titulo?></a>
</h6>
<br>
<p class="colorwhite">
<?=$resumo?>
</p>
</div>
</div>
</div>
<?
}}
?>
</div>
<?
$result -> free();
?>
With this code I was only able to print the second related product that was where string made explode
, I need to print all products, not where it starts.