Utiliser 2 fois while dans une page ?
Bonjour,
Grâce à l'aide de Sabotage, j'ai pu adapter plusieurs page PHP / MYSQL en PHP / PDO mais j'ai un nouveau petit problème, dans cette page j'utilise deux fois le while avec MYSQL et je ne sais pas comment faire avec PDO, de plus je ne sais pas comment compter les rows, j'imagine que c'est avec rowCount, d'après ce que j'ai lu sur le manuel PHP, mais je n'ai pas très bien compris comment l'appliquer à ma page.
Voici la page en PHP / MYSQL
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| <?php
include("menu.php");
//reception de la variable
$id = isset($_POST['truc']) ? $_POST['truc'] : '';
$id = $_POST['truc'];
echo '<br /><center><font color="blue"><big><b>ID concert: ' . $id . '</b></center></font></big>'; //nombre de résultats
?>
<link rel="stylesheet" href="menu/dropdown_three.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">
<style type="text/css">
</style>
<?php
function display($string)
{
echo htmlentities($string, ENT_QUOTES, 'utf8_general_ci ');
}
include("include/variables.inc.php");
$liendb = mysql_connect($bddserver, $bddlogin, $bddpassword);
mysql_select_db ($bdd);
mysql_set_charset( 'utf8' );
$sql = "SELECT *
FROM Tab_NumPlace
INNER JOIN Personnes ON Tab_NumPlace.IDPersonne = Personnes.IDPersonne
INNER JOIN Instruments ON Personnes.IDInstruments = Instruments.IDInstruments
INNER JOIN Concert ON Tab_NumPlace.IDconcert = Concert.IDconcert
INNER JOIN Zones ON Tab_NumPlace.IDZone = Zones.IDZone
INNER JOIN Prix ON Zones.IDPrix = Prix.IDPrix
WHERE Concert.IDconcert = '" . $id . "'
ORDER BY Nom_Personne, Prenom_Personne, Zone, NumPlace";
$resultat = mysql_query ($sql);
$resultat = mysql_query($sql) or die(mysql_error());
while ($Tab_NumPlace = mysql_fetch_array ($resultat))
$result = mysql_query($sql);
$nombre_resultats = mysql_num_rows($result); //compte le nombre d'entrées sélectionnées par la recherche
if ($nombre_resultats == 0) //s'il n'y a pas de résultat
{
echo '<font color="red"><b><big>Aucun resultat </font></big>
<input type="button" onclick="location.href=\''.( ( $variable == 1 ) ? 'listeconcerts.php' : 'listeconcerts.php' ).'\'" value="Recommencer" />';
/*
echo 'aucun resultat.<a href="listeconcerts_resultat.php">recommencer</a>';
*/
}
else //il y a au moins un résultat
{
echo '<br /><br /><center><font color="blue"><b><big>Nombre de places réservées: ' . $nombre_resultats . '</b></center></font></big><br /><br />'; //nombre de résultats
}
if($result)
{
?>
<table class="bicolor" border="1" align="center">
<tr>
<th>Date concert</th>
<th>Zone</th>
<th>Numéro de place</th>
<th>Prix</th>
<th>Reférence</th>
<th>Nom, prénom</th>
</tr>
<?php
while($Tab_NumPlace = mysql_fetch_assoc($result))
{
?>
<tr>
<td><?php display($Tab_NumPlace['dateconcert']); ?></td>
<td><?php display($Tab_NumPlace['Zone']); ?></td>
<td><div class="alindr"><?php display($Tab_NumPlace['NumPlace']); ?></div></td>
<td><div class="alindr"><?php display($Tab_NumPlace['Prix']); ?></div></td>
<td><?php display($Tab_NumPlace['Reférence']); ?></td>
<td><?php display($Tab_NumPlace['Nom_Personne'] . ' - ' . $Tab_NumPlace['Prenom_Personne']); ?></td>
<?php
}
?>
</table>
<br />
<br/>
<center>
<?php
echo '<input type="button" onclick="location.href=\''.( ( $variable == 1 ) ? 'listeconcerts.php' : 'listeconcerts.php' ).'\'" value="Recommencer" />';
?>
</center>
<br />
<center>
<?php
echo '<input type="button" onclick="location.href=\''.( ( $variable == 1 ) ? 'places.php' : 'places.php' ).'\'" value="Voir toutes les places réservées" />';
?>
</center>
<?php
}
mysql_close($liendb);
?> |
Et voici ce que j'ai commencé à faire avec PDO :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| <?php
require 'include/sqlconnect.php';
include("menu.php");
$id = isset($_POST['truc']) ? $_POST['truc'] : '';
$id = $_POST['truc'];
echo '<br /><center><font color="blue"><big><b>ID concert: ' . $id . '</b></center></font></big>'; //nombre de résultats
?>
<link rel="stylesheet" href="menu/dropdown_three.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">
<style type="text/css">
</style>
<?php
function display($string)
{
echo htmlentities($string, ENT_QUOTES, 'utf8_general_ci ');
}
$sth = $bdd->query("SELECT *
FROM Tab_NumPlace
INNER JOIN Personnes ON Tab_NumPlace.IDPersonne = Personnes.IDPersonne
INNER JOIN Instruments ON Personnes.IDInstruments = Instruments.IDInstruments
INNER JOIN Concert ON Tab_NumPlace.IDconcert = Concert.IDconcert
INNER JOIN Zones ON Tab_NumPlace.IDZone = Zones.IDZone
INNER JOIN Prix ON Zones.IDPrix = Prix.IDPrix
WHERE Concert.IDconcert = '" . $id . "'
ORDER BY Nom_Personne, Prenom_Personne, Zone, NumPlace");
while($row = $sth->fetch(PDO::FETCH_ASSOC))
$count = $row->rowCount();
//$nombre_resultats = mysql_num_rows($result); //compte le nombre d'entrées sélectionnées par la recherche
if ($count == 0) //s'il n'y a pas de résultat
{
echo '<font color="red"><b><big>Aucun resultat </font></big>
<input type="button" onclick="location.href=\''.( ( $variable == 1 ) ? 'listeconcerts.php' : 'listeconcerts.php' ).'\'" value="Recommencer" />';
/*
echo 'aucun resultat.<a href="listeconcerts_resultat.php">recommencer</a>';
*/
}
else //il y a au moins un résultat
{
echo '<br /><br /><center><font color="blue"><b><big>Nombre de places réservées: ' . $count . '</b></center></font></big><br /><br />'; //nombre de résultats
}
if($count)
{
?>
<table class="bicolor" border="1" align="center">
<tr>
<th>Date concert</th>
<th>Zone</th>
<th>Numéro de place</th>
<th>Prix</th>
<th>Reférence</th>
<th>Nom, prénom</th>
</tr>
<?php
while($row = $sth->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php display($row['dateconcert']); ?></td>
<td><?php display($row['Zone']); ?></td>
<td><div class="alindr"><?php display($row['NumPlace']); ?></div></td>
<td><div class="alindr"><?php display($row['Prix']); ?></div></td>
<td><?php display($row['Reférence']); ?></td>
<td><?php display($row['Nom_Personne'] . ' - ' . $row['Prenom_Personne']); ?></td>
<?php
}
?>
</table>
<br />
<br/>
<center>
<?php
echo '<input type="button" onclick="location.href=\''.( ( $variable == 1 ) ? 'listeconcerts.php' : 'listeconcerts.php' ).'\'" value="Recommencer" />';
?>
</center>
<br />
<center>
<?php
echo '<input type="button" onclick="location.href=\''.( ( $variable == 1 ) ? 'places.php' : 'places.php' ).'\'" value="Voir toutes les places réservées" />';
?>
</center>
<?php
}
$sth->closeCursor();
?> |
c'est à partir de la ligne 36 ci-dessus.
Merci pour votre aide et bonne soirée