|
Posted by Andrew @ Rockface on 12/06/05 11:34
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 :)
Anyone else have the following pop-up (Firefox 1.0.7) when redirecting
to self. It's just suddenly started happening.
Redirection limit for this URL exceeded.
Unable to load the requested page.
This may be caused by cookies that are blocked.
<?php
$host = "yourhost";
$user = "youruser";
$password = "yourpassword";
$db = "yourdatabase";
$table = "yourtable";
$max = 10; // Max number of inserts
$increment = 2; // 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>");
}
}
}
// Set up a new start and end point then call itself
$start = $c + 1;
$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]
|