title: How do I reduce the execution time in my script in PHP?
body: <p>this is my script, it takes too long , how can I improve the execution time ?</p>
  
  <p>SEE THE ALL OF THE COD: <a href="http://attin.netlogiq.eu/it4profit/feed.txt" rel="nofollow">HERE</a> !</p>
  
  <pre><code>$count_nr_attributes = count($nume);
  $csv[0] = $csv_array_attributes[0];
  for ($i=0; $i &lt; $csv_array_attributes; $i++) { 
  
          if ($i &gt; 0){
              $final = "";
              for ($j=1; $j &lt; $count_nr_attributes; $j++) { 
                  echo "select val_attr from attributes where id_produs = '$csv_array_attributes[$i]' and nume_attr = '$nume[$j]'";echo "&lt;br&gt;";
                  $select = mysql_query("select val_attr from attributes where id_produs = '$csv_array_attributes[$i]' and nume_attr = '$nume[$j]'");
                  $count = mysql_num_rows($select);
                  if ($count == 1){
                      $row = mysql_fetch_array($select);
                      $final .= $row['val_attr']."%%";
                  }else{
                      $final .= "no%%";
                  }
              }
              echo "&lt;hr&gt;";
  
          }
          $csv[$i] = $csv_array_attributes[$i]."%%".$final;
      }
  //create CSV
  $file = fopen("attributes.csv","w+");
      foreach ($csv as $line){
          fputcsv($file,explode('%%',$line),"^","`");
      }
  </code></pre>
  
  <p>The variable <code>$count_nr_attributes</code> contains more then 2500 values and also the $csv_array_attributes contains more then 2500 values. Actually i have two for loops and the execution time takes too long. How can i improve this ? thx</p>
  
  <p>and the query result always return me one value;</p>