سؤال

I have a page which loops though 15,000 entries importing them in to a database. After each 50 entries the user is presented with a continue button.

<form name="contine" method="post" action="<?php echo $continue?>">
    <input type="submit" name="Submit" value="Continue"></input>
</form>

This works well, as it slows the script down so it doesn't load the server (NAS drive running PHP4), and gets around the php page timeout.

$continue contains script name and the current position of the import, so after submission the page will start from there.

I'm trying to do this so the user doesn't need to sit there clicking continue after ever 50 entries. With 15,000 in total it's a lot of clicks.

I've tried using header('Location: '.$continue.'/'); This works if I only try importing around 3,000 entries, any more than that and Chrome complains about looping.

So I'm hoping I can just replace the input button with some javascript that will submit the form for me.

Is that possible and how would I do it ?

Thanks :)

هل كانت مفيدة؟

المحلول

Using plain JS, submit the form using (need to add id="continue" to the form):

document.forms["continue"].submit();

Using jQuery, you can submit the form using the following code:

$('form[name="continue"]').submit();

نصائح أخرى

You could add a oneliner that simply submits your form. additionally you can do this inside a timeout so the user can cancel the process.

You can put a sleep command in before the Location call, and also add in a random string get variable, with a time stamp as a value, so that browsers see a more distinct query string. Obviously your script can ignore the random get Variable...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top