0

i want to do the Pagination using the limit sql function but it shows me an

error that both of $limitt and $start are undefined didn't know the solution.

Produit.php

              public static function vue()
{

     $list = [];
    $db = Db::getInstance();
    $limitt=10;
    if(isset($_GET['page']))
    {
      $page=$_GET['page'];
    }
    else
    {
      $page=1;
    }

    $start=(($page-1)*$limitt);
    $req = $db->query('SELECT * FROM produit WHERE nomCategorie="Vue_Homme" limit $start,$limitt');
    $list=$req->fetchAll(PDO::FETCH_CLASS,'ArrayObject');

    return $list;
}
Slim.aouadi
  • 43
  • 2
  • 9
  • Swap the single and double quotes in your query: `"SELECT * FROM produit WHERE nomCategorie='Vue_Homme' limit $start,$limitt"` – MonkeyZeus May 09 '17 at 13:57
  • Thanks a lot mate i appreciate that :D – Slim.aouadi May 09 '17 at 13:59
  • Because the variables are not in a double-quoted string PHP won't interpret them. Also use parametrized queries, since you are already using pdo, not just passing user input directly, which is very bad and makes you vulnerable to SQL injection. – Tobias F. May 09 '17 at 13:59
  • No problem. Technically your question was closed as a duplicate of a wrong question but I doubt this will get re-opened. Anyways, If you wanted to maintain your original SQL then you would need to break the string literal and concatenate the variables into it: `'SELECT * FROM produit WHERE nomCategorie="Vue_Homme" limit '.$start.','.$limitt` – MonkeyZeus May 09 '17 at 14:00
  • Ohh i see thank you guys for these informations :) – Slim.aouadi May 09 '17 at 14:01
  • Your query need to modified check this one $req = $db->query("SELECT * FROM produit WHERE nomCategorie='Vue_Homme' limit $start,$limitt"); – CyberAbhay May 09 '17 at 14:03

0 Answers0