Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1920 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  Chercher une image en PHP

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Chercher une image en PHP

n°2171929
Escambray
My head in a cloud
Posté le 20-01-2013 à 15:29:28  profilanswer
 

Bonjour, j'aimerais aller chercher une image dans mon dossier image.
 
Voici le code:

Code :
  1. <?php
  2.           include ("connect_db.php" );
  3.            // On récupère les cinq dernières news.
  4.            $req=$bdd->prepare("SELECT * FROM produits ORDER BY Nom" ); // on prépare notre requête
  5.            $req->execute(array());
  6.            $req2=$bdd->prepare("SELECT ref, Nom FROM produits" );
  7.            $req2->execute(fetchAll);
  8.             foreach ($req2 as produits)
  9.             {
  10.              ?><img src="images/<?php echo $produits['Nom']."".$produits['ref']."png";?>"/>
  11.              <?php
  12.             }
  13.             while ($donnees=$req->fetch(PDO::FETCH_ASSOC))
  14.             {
  15.              echo '<tr>';
  16.              echo '<th> N° </th>';
  17.              echo '<th> Apercu </th>';
  18.              echo '<th> Nom </th>';
  19.              echo '<th> Categories </th>';
  20.              echo '<th> Description </th>';
  21.              echo '<th> Stock restant </th>';
  22.              echo '<th> Prix </th>';
  23.              echo '</tr>';
  24.              echo '<tr>';
  25.              echo '<td>'.$donnees['ref'].'.</td>';
  26.              echo '<td>'.$produits.'</td>';
  27.              echo '<td>'.$donnees['Nom'].'</td>';
  28.              echo '<td>'.$donnees['Categories'].'</td>';
  29.              echo '<td>'.$donnees['Description'].'</td>';
  30.              echo '<td>'.$donnees['Stock'].'</td>';
  31.              echo '<td>'.$donnees['Prix'] .'EUR</td>';
  32.              if ($donnees['Stock']<=0)
  33.              {
  34.               echo '<td><img src="images/rupture_stock.png" alt="" />';
  35.              }
  36.              else
  37.              {
  38.               echo '<td><img src="images/en_stock.png" alt="" /></td>';
  39.               echo '<td><form method="POST" action="ajouter_panier.php">';
  40.               echo '<label for="Quantite">Quantite<br /></label><input type="text" name="Quantite" /></td>';
  41.               echo '<td><INPUT border=0 src="images/ajouter_panier.png" type=image Value=submit align="middle" ></td>';
  42.               //echo '<td><a href="ajout_panier.php"><img src="images/ajouter_panier.png" alt="" /></a>';
  43.              }
  44.              echo '</tr>';
  45.             };
  46.          ?>
  47.         </table
  48.        </div>


 
Il me retourne cette erreur: Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM à la ligne du foreach


Message édité par Escambray le 20-01-2013 à 15:43:06
mood
Publicité
Posté le 20-01-2013 à 15:29:28  profilanswer
 

n°2171968
Soileh
Lurkeur professionnel
Posté le 20-01-2013 à 21:41:37  profilanswer
 

Je dirais que fetchAll a l'air d'être une fonction : http://php.net/manual/fr/pdostatement.fetchall.php
alors que tu l'écris de cette façon :

Code :
  1. $req2->execute(fetchAll);


[:spamafote]


---------------
And in the end, the love you take is equal to the love you make
n°2171995
Escambray
My head in a cloud
Posté le 21-01-2013 à 11:02:46  profilanswer
 

ça change rien... :s faudrais vraiment qu'on m'aide svp... je patauge :(

n°2172014
Soileh
Lurkeur professionnel
Posté le 21-01-2013 à 12:22:39  profilanswer
 

Tu as essayé de remplacer la ligne que j'indique par un truc du genre :

Code :
  1. $req2->execute( );
  2. $resultat = $req2->fetchAll( );


:??:


---------------
And in the end, the love you take is equal to the love you make
n°2172016
Escambray
My head in a cloud
Posté le 21-01-2013 à 12:38:15  profilanswer
 

ok, et dans mon foreach je remplace $req2 par $resultats alors?

n°2172125
Soileh
Lurkeur professionnel
Posté le 21-01-2013 à 22:22:49  profilanswer
 

Oui  :jap:  
fetchAll retourne un tableau contenant toutes les lignes du jeu d'enregistrements.


---------------
And in the end, the love you take is equal to the love you make
n°2172126
Escambray
My head in a cloud
Posté le 21-01-2013 à 22:32:43  profilanswer
 

RESOLU MERCI :)


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  Chercher une image en PHP

 

Sujets relatifs
Signature email avec image à coté du texte?[CSS / HTML] Background / Div et image de fond
Map cliquable avec popup image positionné plus[PHP/Linux] Shell_exec
Comment inscrire des variables dans un fichier PHP ? (fwrite)[Divers] Bannière image dynamique
[Java/ANT] Chercher des classes d'un type précisPHP + Sql Server
Modification d'un site PHP, problème affichage page (débutant) 
Plus de sujets relatifs à : Chercher une image en PHP


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR