Question

Suppose I have something like this:

$count = 0; 
foreach($CourseDetails as $course_line) {
    print "<tr><td>{$course_line['class_code']}</td>
            <td>{$course_line['class_name']}</td>
            <td>{$course_line['class_unit']}</td>
            <td>{$course_line['class_description']}</td>
            <td>{$course_line['class_instructors']}</td>";
    $count = $count + 1
    if ($count = 10);
        $count = 0;
        // code that stops script and makes a "Continue?" button pop up on the webpage under the already outputed details
        // if the client presses the "Continue?" button, allow the script to continue (jump back into the foreach loop)
}

I'm trying to find a way to stop the script and then make a button saying "Continue?". If the client presses the button, I want the script to continue where it left off. Does PHP have any functions that allow this?

Was it helpful?

Solution

Short answer: no!

This is more of a workflow design issue. I would suggest creating a list of items to execute. Then try to execute them (as they are successfully processed, mark them as complete), if an error is hit, then stop execution and let the user know. If the user wishes to continue, reload the page, and continue executing the items that have not completed from your initial list.

OTHER TIPS

You can't stop the script once the page has been loaded in the browser. You can only create an interrupt condition inside the script. The two ways for "memory" between pages are either passing an URL variable, e.g. start=20, or using $_SESSION variables to remember the last point of interrupt. Better pass the variable over URL so the pages are individually accessible.

Then, in your loop, simply evaluate whether the entries have a number above the last interrupt. The following presumes your courses are in an array with a numeric index, in which case the $count is redundant. If you're pulling them from a database, take a totally different approach...

$start = !empty($_GET['start']) ? $_GET['start'] : 0;
$offset = 10;

foreach($CourseDetails as $course_num => $course_line) {

    if ($course_num < $start) continue; // These were already seen.

    if ($course_num >= $start + $offset) {
        // Interrupt and make a button that links to ?start=$start+$offset.
        break;
    }

    // Here display stuff.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top