Tableau MySQL > PDO

Résolu/Fermé
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 - 9 avril 2015 à 13:25
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 - 9 avril 2015 à 18:17
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 ?

A voir également:

3 réponses

jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
Modifié par jordane45 le 9/04/2015 à 16:45
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
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
9 avril 2015 à 17:36
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
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
9 avril 2015 à 18:07
Essayes :
$D['Image']

Et si ça ne fonctionne pas.... commence par faire un
print_r($data);
(que tu peux placer linge 6 )
0
Sinistrus Messages postés 1017 Date d'inscription mercredi 12 décembre 2007 Statut Membre Dernière intervention 6 juin 2023 17
9 avril 2015 à 18:17
Hihi, ça marche :p

Merci encore jordane45
0