|  | Posted by Andrew @ Rockface on 12/06/05 12:06 
Andrew @ Rockface wrote:> Freebird wrote:
 >
 >>> How about:
 >>> The insert should start at a given row number and end after 100 rows.
 >>> The script would then call itself with header() and the number of the
 >>> last row inserted + 1.
 >>
 >>
 >>
 >> Did not work, I even did a script that would header location every 1
 >> insert to be SURE that the page will not expire, but header location
 >> just doesn't load the page, doesn't work at all, does anybody have an
 >> example of that ??
 >> Like I said, any piece of code will help, remembering that I can't use
 >> set_time_limit, and header location did not work for me.
 >> Can anyone PLEASE, help me, it seems to be something impossible, I've
 >> asked in everywhere, to everyone, and nothing.
 >
 >
 > This is for postgres but should be easy for you to alter to mysql. It's
 > pretty untested as my server has ben changed in someway that stops me
 > redirecting to the same page - grrr! Or maybe my code is just really
 > crappy :)
 
 Yes it was my crappy code. I forgot to exit when max had been reached.
 Anyway try this as a test:
 
 <?php
 
 $host      = "yourhost";
 $user      = "youruser";
 $password  = "yourpassword";
 $db        = "yourdatabase";
 $table     = "yourtable";
 $max       = 15; // Max number of inserts
 $increment = 3;  // Number of inserts to do on each page load
 
 if (empty($_GET['start'])) {
 $start = 1;
 } else {
 $start = $_GET['start'];
 }
 
 if (empty($_GET['end'])) {
 $end = $increment;
 } else {
 $end = $_GET['end'];
 }
 
 // Connect to db
 $conn = @pg_connect("host=$host dbname=$db user=$user
 password=$password") or
 die("<p>ERROR: No connection to SQL server:
 $db($user)</p><p>".pg_errormessage()."</p>");
 
 // Insert until max or end is reached
 if ($end <= $max) {
 for ($c = $start; $c <= $end; $c++) {
 $sql = "INSERT INTO $table (name) VALUES ('$c')";
 $result = pg_query($conn, $sql);
 if (! $result) {
 die("<p>ERROR: No result from SQL: $sql</p>");
 }
 }
 // Exit when end is max is reached
 } else {
 echo "<p>SUCCESS: Finished insert</p>";
 exit;
 }
 
 // Set up a new start and end point then call itself
 $start = $c;
 $end   = $start + $increment;
 header("Location: ".$_SERVER['PHP_SELF']."?start=$start&end=$end");
 
 ?>
 
 
 --
 Andrew @ Rockface
 np: Air - Sexy Boy [stopped]
 www.rockface-records.co.uk
  Navigation: [Reply to this message] |