PHP mysql
Résolu
nizarkhalloufi
Messages postés
11
Statut
Membre
-
nizarkhalloufi Messages postés 11 Statut Membre -
nizarkhalloufi Messages postés 11 Statut Membre -
Salut tout le monde. Je débute en PHP et j'ai beusoin d'aide svp.
J'essaye d'ecrire une requette sql avec une php
si j'ecris ça ça marche
$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 ' . $numPage . ',2');
mais si
$req = $bdd->prepare('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 ?,2');
$req->execute(array($numPage));
ou
$req = $bdd->prepare('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 :variablePage,2');
$req->execute(array('variablePage'=>$numPage));
ça ne fonctionne pas.
Pouvez vous svp me dire où est ce que j'ai fais erreur ?
J'essaye d'ecrire une requette sql avec une php
si j'ecris ça ça marche
$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 ' . $numPage . ',2');
mais si
$req = $bdd->prepare('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 ?,2');
$req->execute(array($numPage));
ou
$req = $bdd->prepare('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 :variablePage,2');
$req->execute(array('variablePage'=>$numPage));
ça ne fonctionne pas.
Pouvez vous svp me dire où est ce que j'ai fais erreur ?
2 réponses
-
Bonjour,
C'est au niveau du premier paramètre de LIMIT : $numPage est une variable PHP insérer de la bonne façon dans une variable texte. Cette variable peut prendre la valeur que tu veux. C'est donc parfait!
Par contre le point d'interrogation ou le :variablePage n'existe pas que ce soit en PHP ou en MySQL. -
Salut à tous
c'est bon j'ai trouvé comment faire :
$req = $bdd->prepare('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 :numPage, :nombreBilletsPage');
$req->bindParam(':numPage', $numPage, PDO::PARAM_INT);
$req->bindParam(':nombreBilletsPage', $nombreBilletsPage, PDO::PARAM_INT);
$req->execute();