Read phpMyAdmin column

2

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 )
    
asked by anonymous 29.01.2015 / 19:43

1 answer

1
The big problem I was having was that I was not able to store the records after using the explode, as I've been testing this page for a long time so I forgot to loop through the options and store them correctly. The solution I found was simple, see:

    // defini a variável como array
    $subGrupos = array();

    do {

        $string = $row_rsPesquisa['id_subfiltro'];
        // separei os registros por vírgula     
        $array = explode(',', $string); 
        // uni a variável $subGrupo com o array
        $subGrupos = array_merge($subGrupos, $array);   

    } while ($row_rsPesquisa = mysql_fetch_assoc($rsPesquisa));

    // desconsiderei os valores repetidos.
    $array = array_unique($subGrupos);

Here's the code, thanks to everyone who helped me in the comments.

    
30.01.2015 / 00:50