Because my LIMIT does not accept variable

Asked

Viewed 195 times

0

ERROR: it simply does not query when playing on a foreach because LIMIT does not become the variable I declared Does anyone know me?

$cont = 2;

$stm = $pdo->prepare('SELECT sol_camiseta.id, 
                             sol_camiseta.tipo, 
                             sol_camiseta.cor, 
                             sol_camiseta.tamanho, 
                             sol_camiseta.qtd, 
                             sol_camiseta.valor, 
                             sol_camiseta.data_pedido, 
                             pagamento_camiseta.cod_sol_camiseta,
                             pagamento_camiseta.data_pagamento, 
                             pagamento_camiseta.data_retirada 
                             FROM sol_camiseta 
                             INNER JOIN pagamento_camiseta 
                             WHERE sol_camiseta.cod_nome_aluno = :id LIMIT :cont' );

$stm->bindValue( ':id', $_GET['id'] );
$stm->bindValue( ':cont', $cont);
//Executa o pdo
$stm->execute();
$consultas = $stm->fetchAll( PDO::FETCH_ASSOC );

<?php foreach ( $consultas as $consulta ): ?>
                <tr>
                    <td>Tipo:</td>
                    <td><?php echo $consulta['tipo']; ?></td>
                    <td>Cor:</td>
                    <td><?php echo $consulta['cor']; ?></td>
                    <td>Tamanho</td>
                    <td><?php echo $consulta['tamanho']; ?></td>
                    <td>Quantidade</td>
                    <td><?php echo $consulta['qtd']; ?></td>
                    <td>Valor</td>
                    <td><?php echo $consulta['valor']; ?></td>
<?php endforeach; ?>

1 answer

0


Define instead the value for integer, because the clause LIMIT needs the value to be whole.

$stm->bindValue( ':cont', (int) $cont, PDO::PARAM_INT);

PDO::bind - PHP.net

  • Thank you very much guy worked out, I can’t believe it... really

  • You’re welcome -.

Browser other questions tagged

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