Lenteur a cause de 2 requetes
Posté : 30 nov. 2013, 03:24
Bonsoir à tous,
J'ai une petite question pour améliorer la rapidité d'affichage.
J'ai une requete qui va chercher environ 5000 données dans une table et je la met en forme dans un tableau. Mais à chaque ligne je réalise de nouveau une requête pour avoir des informations complèmentaires dans une autre table. Comment faire pour améliorer tout cela ?
Voici le code

J'ai une petite question pour améliorer la rapidité d'affichage.
J'ai une requete qui va chercher environ 5000 données dans une table et je la met en forme dans un tableau. Mais à chaque ligne je réalise de nouveau une requête pour avoir des informations complèmentaires dans une autre table. Comment faire pour améliorer tout cela ?
Voici le code
<?php
if(isset($_SESSION['login']) && $_SESSION['login']!='')
{//Vérification qu'une session existe bien
connect();
?>
<script type="text/javascript">
$(document).ready( function()
{
//Mise en forme des résultat au format Datatable
var oDataTable = $('#table_adh').dataTable({
"bPaginate": false,
"bJQueryUI": true,
"bInfo": true,
"bFilter":true,
});
//Action du click pour afficher la facebox
$('a[rel*=action]').on("click", function() {
$(this).unbind("click").facebox().trigger('click');
return false;
});
});
</script>
<h2>Liste des adhérents</h2>
<?php
//Requete sélection des adherents
$req_adh = 'SELECT id_adh, nom_adh, prenom_adh, tel_adh, etat_adh FROM adherents ORDER BY id_adh ASC';
$res_adh = mysql_query($req_adh);
?>
<table align="center" width="100%" id="table_adh">
<thead>
<tr>
<th>N° Adh</th>
<th>Nom</th>
<th>Prénom</th>
<th>Téléphone</th>
<th>Date Inscription</th>
<th>Durée</th>
<th>Montant</th>
<th>Date de fin</th>
<th>Etat</th>
<th> </th>
</tr>
</thead>
<tbody>
<?php
while($adherent = mysql_fetch_array($res_adh))
{
?>
<tr align="center">
<td><?php echo $adherent['id_adh'];?></td>
<td><a href="?page=detail_adh&id=<?php echo $adherent['id_adh'];?>" class="action"><?php echo $adherent['nom_adh'];?></a></td>
<td><a href="?page=detail_adh&id=<?php echo $adherent['id_adh'];?>" class="action"><?php echo $adherent['prenom_adh'];?></a></td>
<td><?php echo $adherent['tel_adh'];?></td>
<?php
$sql_fact = 'SELECT DISTINCT id_fact, date_fact, duree_fact, montant_fact, id_adh_fact FROM facture WHERE id_adh_fact='.$adherent['id_adh'].' ORDER BY date_fact DESC LIMIT 1';
$req_fact = mysql_query($sql_fact) or die('Erreur SQL !<br>'.$sql_fact.'<br>'.mysql_error());
if(mysql_num_rows($req_fact)>0)
{//Si on a un résultat
while($facture = mysql_fetch_assoc($req_fact))
{
$date_facture_fr = explode('-',$facture['date_fact']);
echo "<td>".$date_facture_fr[2].'/'.$date_facture_fr[1].'/'.$date_facture_fr[0]."</td>";
echo "<td>".$facture['duree_fact']."</td>";
echo "<td>".$facture['montant_fact']." €</td>";
$date_fin = mktime(0,0,0, $date_facture_fr[1] + $facture['duree_fact'], $date_facture_fr[2], $date_facture_fr[0]);
$date_fin_fr=date('d/m/Y',$date_fin);
echo "<td>".$date_fin_fr."</td>";
}
}
else
{
echo "<td>0000/00/00</td>";
echo "<td>0</td>";
echo "<td>0</td>";
echo "<td>0000/00/00</td>";
}
?>
<td><?php echo $adherent['etat_adh'];?></td>
<td align="center">
<a href="pages/adherents/modif_rapid_adherent.php?id=<?php echo $adherent['id_adh'];?>" rel="action" title="Modifier l'adhérent rapidement">
<span class="ui-state-default ui-corner-all ui-icon ui-icon-pencil"></span></a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}//Vérification qu'une session existe bien
?>
Merci d'avance