SELECT COUNT pour un champs prédéfini, et affichage en fonction de son id en PHP
Voila j'explique mon problème, en espérant que quelqu'un pourra m'aider à trouver la solution :aie:
J'ai une table 'logiciel'
contenant 2 champs
logiciel_id INT (11)
logiciel_nom varchar (150)
Je fait une requête afin d'afficher le nombre de tutoriel concernant un logiciel seulement cela ne fonctionne que pour un logiciel que j'ai du définir au préalable !
Ma question est dois-je copier/coller chaque parcelle de requete SQL(voir code ci dessous), cela risque de devenir illisible car j'ai plus de 22 logiciels dans ma base de données.:cry:
Voici un aperçu du code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
// type de tutoriel PREMIUM 'OPEN OFFICE'
$compteP =mysql_query('SELECT COUNT(DISTINCT ttr_id)
FROM tutoriel
LEFT JOIN logiciel
ON tutoriel.logiciel_id = logiciel.lgc_id
AND tutoriel.ttr_type = "P"
WHERE logiciel.lgc_nom = "OPEN OFFICE"
ORDER BY ttr_id
');
$affichage_resultat =mysql_fetch_row($compteP);
// compte type de tutoriel MEMBRE "Open Office"
$compteG =mysql_query('SELECT COUNT(DISTINCT ttr_id)
FROM tutoriel
LEFT JOIN logiciel
ON tutoriel.logiciel_id = logiciel.lgc_id
AND tutoriel.ttr_type = "M"
WHERE logiciel.lgc_nom = "Open Office"
ORDER BY ttr_id
');
$affichage_resultatG =mysql_fetch_row($compteG); |
et voici un autre bout de code pour afficher les résultats cette fois ci ;
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
|
<a href="open-office.php" class="info">
<div class="max">
<span style="position: absolute; font-family: verdana sans-serif; font-size: 12px; padding: 22px 15px 15px 50px;">
<?php $data =mysql_fetch_assoc($ttr_result)?>
<p class="min-title">
<fieldset style="position: absolute; width: 120px; height: 110px; padding: 8px; border-radius: 10px 10px 10px 10px; top: 2px; border: 1px solid silver; left: 1px;">
<p style="font-weight: bold; font-size: 16px; position: absolute; top: -14px; color: whitesmoke; text-shadow: 1px 1px 1px black;"><?php echo ($data['lgc_nom']); ?></p></p>
<p class="min-info">
<?php echo $data['ttr_title']; ?></p>
<p class="min-nbr">
<strong style="color: white; text-shadow: 1px 1px 1px black; text-decoration: underline; font-weight: bold; position: absolute; top: -1px; font-size: 13px; left: -17px;">
<?php echo $affichage_resultat['0']; ?></strong> tuto(s) payant(s) <br>
<strong style="color: white; text-shadow: 1px 1px 1px black; text-decoration: underline; font-weight: bold; position: absolute; top: 15px; font-size: 13px; left: -17px;">
<?php echo $affichage_resultatG['0']; ?></strong> tuto(s) gratuit(s)</p>
<hr style="position: relative; top: 42px;">
<p class="min-duree">Durée:
<b style="font-size: 11px; color: greenyellow; position: absolute; top: 1px; left: 32px;">
<?php echo $data['ttr_temps']; ?></b>
<b style="position: absolute; top: 2px; color: greenyellow; font-size: 10px; left: 49px;">min</b></p>
<p class="min-date">Le : <b style="font-size: 11px; color: greenyellow; position: absolute; left: 20px; top: 1px;">
<?php echo $data['ttr_date']; ?></b> </p>
<div class="text">
<?php // Code qui compte les mot
$msg = $data['ttr_desc'];
$tab=str_word_count($msg,2);
$mot=array_keys($tab);
if(count($mot)>10)
{
echo substr($msg,0,$mot[10]);
echo '...';
}
else
{
echo $msg ;
}
?>
</div></fieldset>
<p class="min-image">
<?php echo '<img style="border-radius: 5px 5px 10px 10px ;" src="' . $data["image_popup"] . '" />'; ?> </p>
</span>
</div>
</a> |