Because my LIMIT does not accept variable [duplicate]

0

ERROR: it simply does not query when I play in a foreach because LIMIT does not become the variable I declare Does anyone know how to do it?

$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; ?>
    
asked by anonymous 11.10.2015 / 06:25

1 answer

0

Defines the value for integer, because the LIMIT clause needs the value to be integer .

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

PDO :: bind - PHP.net

    
11.10.2015 / 07:17