Query in php and mysql in a table

0

I am having problems with a query, I have a combobox to make the query and it is displayed in a table. I do it in the following way:

$where="";
$fun=$_POST['funcion']; 
if (isset($_POST['buscar']))
{
   $where="where tipo_funcion='".$fun."' and status='Activo'";  
}
//Consulta 
$q="SELECT * FROM utrans_archivos_seccion WHERE status='Activo' $where"; 
$resFun=$con->query($q);

 <!-- Creamos la tabla para mostrar dentro de ella lo que el usuario esta pidiendo y consultando -->
        <table class="table">
                <tr>
                <!-- Columnas por las que vamos a acomodar la información en la tabla -->
                    <th></th>
                    <th>Código Sección</th>
                    <th>Sección</th>
                </tr>

                <?php
                //Metemos un while para que jale la información de la base de datos
                while ($regFun = $resFun->fetch_array(MYSQLI_BOTH))
                {

                    echo'<tr>
                         <td><input type="checkbox" name="eliminar[]" value="'.$regFun['seccion_id'].'" /> </td>
                         <td>'.$regFun['codigo_seccion'].'</td>
                         <td>'.$regFun['seccion'].'</td>
                         </tr>';
                }
                ?>
            </table>

The problem is that it shows me in the table the records that are active and until then all "well" but at the time of making the query it does not, I feel that the $ where variable may be the one that is affecting,

    
asked by user67189 22.11.2017 в 21:02
source

1 answer

0

try this

$where="";
$fun=$_POST['funcion']; 
if (isset($_POST['buscar']))
{
   $where=" where tipo_funcion='".$fun."' and status='Activo'";  
}
else
{
   $where=" WHERE status='Activo'";  
}
//Consulta 
$q="SELECT * FROM utrans_archivos_seccion '".$where."'"; 
$resFun=$con->query($q);

 <!-- Creamos la tabla para mostrar dentro de ella lo que el usuario esta pidiendo y consultando -->
        <table class="table">
                <tr>
                <!-- Columnas por las que vamos a acomodar la información en la tabla -->
                    <th></th>
                    <th>Código Sección</th>
                    <th>Sección</th>
                </tr>

                <?php
                //Metemos un while para que jale la información de la base de datos
                while ($regFun = $resFun->fetch_array(MYSQLI_BOTH))
                {

                    echo'<tr>
                         <td><input type="checkbox" name="eliminar[]" value="'.$regFun['seccion_id'].'" /> </td>
                         <td>'.$regFun['codigo_seccion'].'</td>
                         <td>'.$regFun['seccion'].'</td>
                         </tr>';
                }
                ?>
            </table>
    
answered by 22.11.2017 в 21:40