Bonjour,
j'ai une base de donnees avec 2 tables : annonces_search et annonces_images
1ere table "tables annonces_search" voici les champs :
id_reg
id_dep
id_cat
code_pos
status
type
titre
ann
prix
etat
date
id_compte
photo
video
urg
une
2nd table "annonces_images" voici les champs :
id_ima
id_ann
nom
actuellement j'ai cela dans mon code ci dessous
$reponse = $bdd->query('SELECT * FROM PAG_annonces where type=1 order by id_ann desc limit 0,5');
qui me sort les 5 dernières annonces EN TEXTE. Mais il me manque les images associées à ces annonces; en gros je souhaiterais rajouter ceci
JOIN annonces_images where id_ann= id_ann de annonces_search
afin que les images sortent avec les annonces mais je n'y arrive pas.
si quelqu'un pouvait m'aider.
merci
ceci ne fonctionne pas !!!!!!!!!!!!!!!
$reponse = $bdd->query('SELECT * FROM PAG_annonces LEFT JOIN ". PREFIX ."annonces_images o ON s.id_ann = o.id_ann where type=1 order by id_ann desc limit 0,5');
*******************************
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?php
echo 'les 5 dernieres annonces' ;
try {
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=MON SERVEUR;dbname=MA DATABASE', 'LOGIN', 'MDP', $pdo_options); // selection de ma database
$reponse = $bdd->query('SELECT * FROM PAG_annonces where type=1 order by id_ann desc limit 0,5'); // 5 dernieres annonces
while ($donnees = $reponse->fetch()){
echo utf8_encode (' <a href="ann_page.php?id='.$donnees['id_ann'] . '" title="'.$donnees['titre'] .' a '.$donnees['ville'] .'">'.$donnees['titre'] .'<a/><br>');
}
$reponse->closeCursor();
}
catch(Exception $e){
die('Erreur : '.$e->getMessage());
}
?> |
Partager