SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Querys problem

    Hi!
    i hope someone have some tips how i can code for this beacuse it take to long time so it only print a blank page

    i have about 500 querys like this:
    PHP Code:
    // Affärssystem
    $query "SELECT projektnr, COUNT(foretag) FROM intervjuer WHERE  $leadsfraga1429 like '$utslagsfraga1429' OR ( $leadsfraga14291 like '$utslagsfraga1429' ) OR ( $leadsfraga14292 like '$utslagsfraga1429' ) GROUP BY projektnr DESC limit 1";      
    $result mysql_query($query) or die(mysql_error());
    // Print out result
    while($row mysql_fetch_array($result)){
        echo 
    ""$row['projektnr'] ." Affärsystem "$row['COUNT(foretag)'] ." ";
        echo 
    "<br />";
    }
    // Arbetsbord
    $query "SELECT projektnr, COUNT(foretag) FROM intervjuer WHERE  $leadsfraga1034 like '$utslagsfraga1034' GROUP BY projektnr DESC limit 1";      
    $result mysql_query($query) or die(mysql_error());
    // Print out result
    while($row mysql_fetch_array($result)){
        echo 
    ""$row['projektnr'] ." Arbetsbord "$row['COUNT(foretag)'] ." ";
        echo 
    "<br />";
    }
    // Arbetsmiljöutbildning
    $query "SELECT projektnr, COUNT(foretag) FROM intervjuer WHERE $leadsfraga1446 like '$utslagsfraga1446' GROUP BY projektnr DESC limit 1";      
    $result mysql_query($query) or die(mysql_error());
    // Print out result
    while($row mysql_fetch_array($result)){
        echo 
    ""$row['projektnr'] ." Arbetsmiljöutbildning  "$row['COUNT(foretag)'] ." ";
        echo 
    "<br />";

    Is there a better way to print out this ( notice that every query has a specific name like ( echo "". $row['projektnr'] ." Arbetsmiljöutbildning ". $row['COUNT(foretag)'] ." "; ) so i need to get the same results but faster

    Hope you guys understand what i mean :-)

    /Tony
    Last edited by SpacePhoenix; Nov 22, 2011 at 10:54. Reason: swapped code tags for php tags around the code

  2. #2
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    967
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Its hard to tell exactly what you are doing here, but it does look very inefficient. The queries and outputs look very similar.
    It seems like there should be some way to do this with one query. In your output, only the middle word is different. Could that be stored in the database?
    Finding some method that is more flexible and doesn't rely on so much one off processes is the key.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In every query it´s a different search for results then i print out the answers for each different question
    the problem is that i need to control what the outpost are like echo "". $row['projektnr'] ." Arbetsmiljöutbildning ". $row['COUNT(foretag)'] ." ";
    that means that the search of " Arbetsmiljöutbildning " is outprinted from the database where the question and search parameter i correct ( SELECT projektnr, COUNT(foretag) FROM intervjuer WHERE $leadsfraga1446 like '$utslagsfraga1446' GROUP BY projektnr DESC limit 1 ) and only shows the last "projektnr" stored in the database

    No, i cant store the names in the database


Bookmarks

Posting Permissions

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