Tableau MySQL > PDO

Résolu
Sinistrus Messages postés 1010 Date d'inscription   Statut Membre Dernière intervention   -  
Sinistrus Messages postés 1010 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour à tous !

Je suis en train de convertir mes pages en PDO et je sollicite votre aide.

Voici le code en MySQL
<?php
$NbrCol = 6;
$query = "SELECT * FROM ".$TB_MARQUES." WHERE ".$PAYS."='1' AND Menu='1' ORDER BY Marque ASC;";

$result = mysql_query($query);
$NbreData = mysql_num_rows($result);

$NbrLigne = 0;
if ($NbreData != 0) {
$j = 1;
?>
	<table width="100%" border="0" cellspacing="10" cellpadding="0">
	<tbody>
<?php while($data = mysql_fetch_array($result)) {if ($j%$NbrCol == 1) {$NbrLigne++;$fintr = 0; ?>
<tr>
<?php } ?>
<td align="center" valign="middle">

<a href="<?php echo URL_RACINE; ?>/categories/<?php echo $data['Lien']; ?>">
<img src="<?php echo URL_IMAGES; ?>/logos/<?php echo $data['Image']; ?>" width="159" height="80" title="<?php echo $data['Descriptions']; ?>" alt="<?php echo $data['Marque']; ?>" />
</a>

</td>
<?php if ($j%$NbrCol == 0) {$fintr = 1; ?>
</tr>
<?php }$j++;} if ($fintr!=1) { ?>
</tr>
<?php } ?>
</tbody>
</table>
	
<?php } ?>


J'ai essayé ceci mais il ne fonctionne pas...
<?php
	$NbrCol = 6;
$statement = $pdo->query("SELECT * FROM ".$TB_MARQUES." WHERE ".$PAYS."='1' AND Menu='1' ORDER BY Marque ASC");
$data  = $statement->fetch(PDO::FETCH_ASSOC);

//$result = $statement;
$NbreData = $statement;

	$NbrLigne = 0;
	if ($NbreData != 0){
	$j = 1;

?>



	<table width="100%" border="0" cellspacing="10" cellpadding="0">
	<tbody>
<?php while($data){if ($j%$NbrCol == 1) {$NbrLigne++;$fintr = 0; ?>
<tr>
<?php } ?>
<td align="center" valign="middle">

<a href="<?php echo URL_RACINE; ?>/categories/<?php echo $data['Lien']; ?>">
<img src="<?php echo URL_IMAGES; ?>/logos/<?php echo $data['Image']; ?>" width="159" height="80" title="<?php echo $data['Descriptions']; ?>" alt="<?php echo $data['Marque']; ?>" />
</a>

</td>
<?php if ($j%$NbrCol == 0) {$fintr = 1; ?>
</tr>
<?php }$j++;} if ($fintr!=1) { ?>
</tr>
<?php } ?>
</tbody>
</table>
	
<?php } ?>


Pouvez-vous me filer un coup de main svp ?

3 réponses

  1. jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention   4 831
     
    Bonjour,

    Là comme ça.. je dirais :
    $NbrCol = 6;
    $statement = $pdo->query("SELECT * FROM ".$TB_MARQUES." WHERE ".$PAYS."='1' AND Menu='1' ORDER BY Marque ASC");
    $data  = $statement->fetchAll();
    $NbreData = count($data);
    
    $NbrLigne = 0;
    if ($NbreData >0){
     $j = 1;
    ?>
     <table width="100%" border="0" cellspacing="10" cellpadding="0">
     <tbody>
    <?php 
     foreach($data as $D){
       if ($j%$NbrCol == 1) {
             $NbrLigne++;$fintr = 0; 
       echo "<tr>";
      }
     ?>
    


    Cordialement,
    Jordane
    0
  2. Sinistrus Messages postés 1010 Date d'inscription   Statut Membre Dernière intervention   17
     
    Merci pour ton aide jordane45... mais je n'ai rien qui s'affiche :
    <?php
    $NbrCol = 6;
    $statement = $pdo->query("SELECT * FROM ".$TB_MARQUES." WHERE ".$PAYS."='1' AND Menu='1' ORDER BY Marque ASC");
    $data  = $statement->fetchAll();
    $NbreData = count($data);
    
    $NbrLigne = 0;
    if ($NbreData >0){
     $j = 1;
    ?>
     <table width="100%" border="0" cellspacing="10" cellpadding="0">
     <tbody>
    <?php 
     foreach($data as $D){
       if ($j%$NbrCol == 1) {
             $NbrLigne++;$fintr = 0; 
    ?>
    
    <tr>
    <?php } ?>
    <td align="center" valign="middle">
    
    <a href="<?php echo URL_RACINE; ?>/categories/<?php echo $data['Lien']; ?>">
    <img src="<?php echo URL_IMAGES; ?>/logos/<?php echo $data['Image']; ?>" width="159" height="80" title="<?php echo $data['Descriptions']; ?>" alt="<?php echo $data['Marque']; ?>" />
    </a>
    
    </td>
    <?php if ($j%$NbrCol == 0) {$fintr = 1; ?>
    </tr>
    <?php }$j++;} if ($fintr!=1) { ?>
    </tr>
    <?php } ?>
    </tbody>
    </table>
    	
    <?php } ?>


    J'ai essayé avec
    $data->Image
    mais là aussi ça ne fonctionne pas !
    0
    1. jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention   4 831
       
      Essayes :
      $D['Image']

      Et si ça ne fonctionne pas.... commence par faire un
      print_r($data);
      (que tu peux placer linge 6 )
      0
  3. Sinistrus Messages postés 1010 Date d'inscription   Statut Membre Dernière intervention   17
     
    Hihi, ça marche :p

    Merci encore jordane45
    0