...

View Full Version : Optimizing mysql queries



myrveln
11-05-2007, 12:08 PM
Hey

I have a feeling that this isnīt very optimal. Is there a way where you can put all these mysql queries into one or more fewer than this?

This way works great, though a bit too much queries.

Any ideas appreciated.


$querytotal = mysql_query("SELECT id FROM $db WHERE date_pub='$week' AND visible='0'");
$numtotal = mysql_num_rows($querytotal);
$query_1 = mysql_query("SELECT id FROM $db WHERE date_pub='$week' AND type='1' AND visible='0'");
$num1 = mysql_num_rows($query_1);
$query_2 = mysql_query("SELECT id FROM $db WHERE date_pub='$week' AND type='2' AND visible='0'");
$num2 = mysql_num_rows($query_2);
$query_3 = mysql_query("SELECT id FROM $db WHERE date_pub='$week' AND type='3' AND visible='0'");
$num3 = mysql_num_rows($query_3);
if($numrow > 0){
print "Print out the content\n\n";
}

Mwnciau
11-05-2007, 12:28 PM
$querytotal = mysql_query("SELECT COUNT(type) as ctype, type FROM $db WHERE date_pub='$week' AND visible='0' GROUP BY type");
while($row = mysql_fetch_array($querytotal)){
echo 'There are '.$row['ctype'].' of type '.$row['type']'.<br />';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum