Rendre LIMIT variable

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Rendre LIMIT variable

Re: Rendre LIMIT variable

par devlop78 » 18 juil. 2011, 00:26

Je vais te donner un indice :
echo "test \' test \ test \\ test \" ok</br>";

echo 'test \' test \ test \\ test \" ok</br>';
donne :
test \' test \ test \ test " ok
test ' test \ test \ test \" ok

Rendre LIMIT variable

par poliboolold » 16 juil. 2011, 14:33

Bonjour j'ai des problèmes avec LIMIT . J'aimerais le rendre variable

Or regardez si je fait comme ca (code a la fin)
ca m'affiche cette erreur:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'%d/%m/%Y à %Hh%imin%ss\') AS date_creation_fr FROM billets ORDER BY date_creat' at line 1' in /var/www/poliboolold.fr/htdocs/blog/blog.php:35 Stack trace: #0 /var/www/poliboolold.fr/htdocs/blog/blog.php(35): PDO->query('SELECT id, titr...') #1 {main} thrown in /var/www/poliboolold.fr/htdocs/blog/blog.php on line 35

sans variable ca marche correctement:

le code (merci d'avance :wink: )

Code : Tout sélectionner

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"> <head> <title>Mon blog</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Mon super blog !</h1> <p>Derniers billets du blog :</p> <?php // Connexion à la base de données try { $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $bdd = new PDO('mysql:host=*************;dbname=polib250634', 'polib250634', '**********',$pdo_options); } catch(Exception $e) { echo '<p>Erreur PDO dans '.$e->getFile().' L.'.$e->getLine().' : <br/> '.$e->getMessage().'<br /></p>'; } $compter= $bdd->query('SELECT COUNT(id) AS nombre FROM billets'); $resultat= $compter->fetch(); $nombre_article=$resultat['nombre']; $perpage=4; $pagecourante=1; $compter->closeCursor(); // On récupère les 5 derniers billets $req = $bdd->query("SELECT id, titre, contenu, DATE_FORMAT(date_creation, \'%d/%m/%Y à %Hh%imin%ss\') AS date_creation_fr FROM billets ORDER BY date_creation DESC LIMIT 0,$perpage") or die(print_r($bdd->errorInfo())); while ($donnees = $req->fetch()) { ?> <div class="news"> <h3> <?php echo htmlspecialchars($donnees['titre']); ?> <em>le <?php echo $donnees['date_creation_fr']; ?></em> </h3> <p> <?php // On affiche le contenu du billet echo nl2br(htmlspecialchars($donnees['contenu'])); ?> <br /> <em><a href="commentaires.php?billet=<?php echo $donnees['id']; ?>">Commentaires</a></em> </p> </div> <?php } // Fin de la boucle des billets $req->closeCursor(); ?> </body> </html>