Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP nested problems while querying
    primarykey
    data
    text
    <p>I am working on a project. I need to query a DB and write the result to a csv file. The result is going to be over 15,000 entries, (thats what the user wants). I am breaking up the results using the LIMIT because if I don't the DB will time out. I divide the query in what I call total_pages. Here is my code.</p> <p>The big for loop, loops 19 times. The problems is that the code will go through the nested loop one time ( only 500 entries) then It does not go back in. I tried using null on the $results but no luck. Please help.</p> <pre><code>// using this for my LIMIT $start_from = 0; $sql = "select * from someplace where gender = '".$gender."'"; $rs_result = mysql_query($sql); $total_records = mysql_num_rows($rs_result); $total_pages = ceil($total_records / 500); // open a file //write x in file file = fopen("./DataFile/gdownload.csv","w"); //write header to the file $x = "Last Name,First Name,Primary_Name, ........ etc...... \n"; fwrite($file, $x); for($count = 0; $count &lt;= $total_pages; $count++) { $query = "SELECT * FROM ptable JOIN person_name ON ptable.Primary_Name = person_name.Primary_Name WHERE gender = '$gender' ORDER BY person_name.Lname ASC LIMIT ".$start_from.", 500"; $result = mysql_query($query) or die(mysql_error()); $num_row = mysql_num_rows($result); //print tables in rows while($row = mysql_fetch_array($result)) { $x=""; $x=$x.$row['Lname'].","; $x=$x.$row['Fname'].","; $x=$x.$row['Primary_Name'].","; $x=$x.$row['asdf#'].","; $x=$x.$row['qwer'].","; $x=$x.$row['hjkl'].","; $x=$x.$row['bnm,'].","; $x=$x.$row['yui'].","; $x=$x.$row['aaa'].","; ..... fwrite($file, $x); }// end nested while $start_from+=500; }// end for loop fclose($file); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload