Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Optimizing mysql queries

    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.

    PHP Code:
    $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";


  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    $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 />';



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •