Why not Filter Select Like in Mysql Php Page

Asked

Viewed 86 times

-2

Hello I’m having the same problem in my database table where the daily field exists

some records are with the following data in the diasemana field = Monday Tuesday Wednesday Thursday Friday

and other days = Tuesday Thursday, other days = Monday, other days only Wednesday

On Phpmyadmin when I put the Command Line

Select * from grade Where diasemana Like '%Segunda%';

It returns correctly

But in my php page where is the script below pagination

 //verifica a página atual caso seja informada na URL, senão atribui como 1ª página
    $pagina = (isset($_GET['pagina']))? $_GET['pagina'] : 1;

    //$diasemana = trim(strip_tags($_GET['diasemana']));
    #$data = $pdo->query("SELECT * FROM produtos");

$diasemana = trim(strip_tags("Terça"));


//seleciona todos os itens da tabela
$cmd = "Select * from table Where diasemana Like '%".$diasemana."%'";

try {

        $query = $pdo->prepare($cmd);
        $query->execute();


//conta o total de itens
   $total = $query->rowCount();

   //echo $total;

//seta a quantidade de itens por página, neste caso, 2 itens
$registros = 20;

//calcula o número de páginas arredondando o resultado para cima
$numPaginas = ceil($total/$registros);

//variavel para calcular o início da visualização com base na página atual
 $inicio = ($registros*$pagina)-$registros;

 //seleciona os itens por página (segunda query sobrepondo a anterior
 $cmd = "select * from table limit $inicio,$registros";
 $query = $pdo->prepare($cmd);
 $query->execute();

 //reconta o total de itens
   $total = $query->rowCount();



#while($linha = $query->fetch(PDO::FETCH_ASSOC)){ 




?>

Well in summary - on the server-side Php page it is not filtering what may be happening if someone can give me a help already thank you

2 answers

0

Hello Renan first thank you but I just put table and forgot only to not show the name of the table but even in grid does not return the query would be the version of Msql Pdo I am not using Mysqli?

0

Your SELECT on the command line is different from SELECT in PHP:

$cmd = "Select * from table Where diasemana Like '%".$diasemana."%'";

Select * from grade Where diasemana Like '%Segunda%';

Based on that, the right thing would be:

$cmd = "SELECT * FROM grade WHERE diasemana LIKE '%".$diasemana."%'";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.