I was able to separate some values from a column in a table in PhpMyAdmin through some tips and I did this:
mysql_select_db($database_conexao, $conexao);
if ($dep != "" and $sub != "") {
$query_rsPesquisa = "SELECT * FROM 'produtos' WHERE id_departamento = $dep AND id_subdepartamento = $sub";
} else {
$query_rsPesquisa = "SELECT * FROM 'produtos' WHERE id_departamento = $dep";
}
$rsPesquisa = mysql_query($query_rsPesquisa, $conexao) or die(mysql_error());
$row_rsPesquisa = mysql_fetch_assoc($rsPesquisa);
$totalRows_rsPesquisa = mysql_num_rows($rsPesquisa);
$string = $row_rsPesquisa['id_subfiltro'];
$array = explode(',', $string);
And then to look up the description of each id in a specific table and show it on my page, I did this:
<?php
if ($dep != "" and $sub != "") {
foreach ($array as $valores) {
mysql_select_db($database_conexao, $conexao);
$query_rsSub = "SELECT * FROM subfiltro WHERE id_subfiltro = $valores";
$rsSub = mysql_query($query_rsSub, $conexao) or die(mysql_error());
$row_rsSub = mysql_fetch_assoc($rsSub);
$totalRows_rsSub = mysql_num_rows($rsSub);
$descProd = $row_rsSub['descricao'];
echo "<ul class='menu2'>
<li><a href='#'>$descProd</a></li>
<li class='current-menu-item'></li>
</ul>";
}
}
?>
But what's weird is that my first select
is not getting all the values in my id_subfiltro column, it looks like for the first, see the following image:
Thepageisthis: Developing page
The values that I need to redeem in this case would be 8,2,61,155,6,17,16,176,117 .
But I'm returning this:
Array ( [0] => 8 [1] => 2 [2] => 61 [3] => 155 [4] => 6 [5] => 17 )