Rassembler des requetes while

  • Auteur de la discussion Auteur de la discussion sff
  • Date de début Date de début
WRInaute impliqué
Bonjours, je cherche comment je pourrais faire pour rassembler les 3 requetes select en une seule, mais j'ai un peu de mal. Avez vous une idée? Merci


// Download type 1.
$downloadquery = doquery("SELECT * FROM {{table}} WHERE type='1'", "download");

$downloadrow = 0;
$page['type1'] ='';

while ($downloadrow = mysql_fetch_array($downloadquery))
{
$page['type1'] .='<div class="bloc_rose"><div style="float:left"><a href="#" onmouseover="montre(\'<img src='.$downloadrow['image'].'>\');" onmouseout="cache();"><img src="'.$downloadrow['image'].'" alt="'.$downloadrow['title'].'" style="height:40px; width:40px" class="no_bordure"></a></div><a href="?do=download&id='.$downloadrow['id'].'"><b><span class="mauve2">'.$downloadrow['title'].'</span></b></a> - <i>Téléchargé: <span class="mauve1">'.$downloadrow['count'].'</span> fois</i><br><span class="taille1">'.$downloadrow['content'].'</span></div><br>';

}

// Download type 2.
$downloadquery = doquery("SELECT * FROM {{table}} WHERE type='2'", "download");

$downloadrow = 0;
$page['type2'] ='';

while ($downloadrow = mysql_fetch_array($downloadquery))
{
$page['type2'] .='<div class="bloc_rose"><div style="float:left"><a href="#" onmouseover="montre(\'<img src='.$downloadrow['image'].'>\');" onmouseout="cache();"><img src="'.$downloadrow['image'].'" alt="'.$downloadrow['title'].'" style="height:40px; width:40px" class="no_bordure"></a></div><a href="'.$downloadrow['url'].'"><b><span class="mauve2">'.$downloadrow['title'].'</span></b></a> - <i>Téléchargé: <span class="mauve1">'.$downloadrow['count'].'</span> fois</i><br><span class="taille1">'.$downloadrow['content'].'</span></div><br>';
}

// Download type 3.
$downloadquery = doquery("SELECT * FROM {{table}} WHERE type='3'", "download");

$downloadrow = 0;
$page['type3'] ='';

while ($downloadrow = mysql_fetch_array($downloadquery))
{
$page['type3'] .='<div class="bloc_rose"><div style="float:left"><a href="#" onmouseover="montre(\'<img src='.$downloadrow['image'].'>\');" onmouseout="cache();"><img src="'.$downloadrow['image'].'" alt="'.$downloadrow['title'].'" style="height:40px; width:40px" class="no_bordure"></a></div><a href="'.$downloadrow['url'].'"><b><span class="mauve2">'.$downloadrow['title'].'</span></b></a> - <i>Téléchargé: <span class="mauve1">'.$downloadrow['count'].'</span> fois</i><br><span class="taille1">'.$downloadrow['content'].'</span></div><br>';
}
 
WRInaute impliqué
suite

Merci pour l'aide, c'est déja mieu la. Mais je suis persuadé qu'on peu encore réduire ca.

$downloadquery = doquery("SELECT * FROM {{table}} WHERE type IN ('1', '2', '3') ORDER BY type", "download");

$downloadrow = 0;
$page['type1'] = $page['type2'] = $page['type3'] = null;

while ($downloadrow = mysql_fetch_array($downloadquery))
{
$type = '<div class="bloc_rose"><div style="float:left"><a href="#" onmouseover="montre(\'<img src='.$downloadrow['image'].'>\');" onmouseout="cache();"><img src="'.$downloadrow['image'].'" alt="'.$downloadrow['title'].'" style="height:40px; width:40px" class="no_bordure"></a></div><a href="?do=download&url='.$downloadrow['url'].'&id='.$downloadrow['id'].'"><b><span class="mauve2">'.$downloadrow['title'].'</span></b></a> - <i>Téléchargé: <span class="mauve1">'.$downloadrow['count'].'</span> fois</i><br><span class="taille1">'.$downloadrow['content'].'</span></div><br>';

if ($downloadrow['type'] = 1) {
$page['type1'] .= $type;
}elseif ($downloadrow['type'] = 2) {
$page['type2'] .= $type;
}elseif ($downloadrow['type'] = 3) {
$page['type3'] .= $type;}
}
 
WRInaute accro
Re: suite

sff a dit:
Merci pour l'aide, c'est déja mieu la. Mais je suis persuadé qu'on peu encore réduire ca.

$downloadquery = doquery("SELECT * FROM {{table}} WHERE type IN ('1', '2', '3') ORDER BY type", "download");

$downloadrow = 0;
$page['type1'] = $page['type2'] = $page['type3'] = null;

while ($downloadrow = mysql_fetch_array($downloadquery))
{
$type = '<div class="bloc_rose"><div style="float:left"><a href="#" onmouseover="montre(\'<img src='.$downloadrow['image'].'>\');" onmouseout="cache();"><img src="'.$downloadrow['image'].'" alt="'.$downloadrow['title'].'" style="height:40px; width:40px" class="no_bordure"></a></div><a href="?do=download&url='.$downloadrow['url'].'&id='.$downloadrow['id'].'"><b><span class="mauve2">'.$downloadrow['title'].'</span></b></a> - <i>Téléchargé: <span class="mauve1">'.$downloadrow['count'].'</span> fois</i><br><span class="taille1">'.$downloadrow['content'].'</span></div><br>';

if ($downloadrow['type'] = 1) {
$page['type1'] .= $type;
}elseif ($downloadrow['type'] = 2) {
$page['type2'] .= $type;
}elseif ($downloadrow['type'] = 3) {
$page['type3'] .= $type;}
}

Avec un switch au lieu de tes if elseif
 
WRInaute impliqué
suite

Comme ca? Visiblement ca fonctionne. On peut encore mieu faire?

$downloadquery = doquery("SELECT * FROM {{table}} WHERE type IN ('1', '2', '3') ORDER BY type", "download");

$downloadrow = 0;
$page['type1'] = $page['type2'] = $page['type3'] = null;

while ($downloadrow = mysql_fetch_array($downloadquery))
{
$type = '<div class="bloc_rose"><div style="float:left"><a href="#" onmouseover="montre(\'<img src='.$downloadrow['image'].'>\');" onmouseout="cache();"><img src="'.$downloadrow['image'].'" alt="'.$downloadrow['title'].'" style="height:40px; width:40px" class="no_bordure"></a></div><a href="?do=download&url='.$downloadrow['url'].'&id='.$downloadrow['id'].'"><b><span class="mauve2">'.$downloadrow['title'].'</span></b></a> - <i>Téléchargé: <span class="mauve1">'.$downloadrow['count'].'</span> fois</i><br><span class="taille1">'.$downloadrow['content'].'</span></div><br>';

switch($downloadrow['type']) {
case '1': $page['type1'] .= $type; break;
case '2': $page['type2'] .= $type; break;
case '3': $page['type3'] .= $type; break;
}
}
 
Discussions similaires
Haut