Jump to content

loop through pages


poe

Recommended Posts

i have a series of pages:

a.php, b.php, c.php, d.php etc...

i want to click my start button and it will show and run the code on page 'a' then after the code is run, it will jump to page 'b' etc...

at the bottom of every page it will show a status table. so as each page is run it will show page '?' = updated.

i am planning to use sessions to store what pages have been run.

i want to store the pages that need to run
$_SESSION['pages'] = 'pga,pgb,pgc,pgd,pge';


so as each page is run i will set the session.

my question is.. am i better setting a session for each page:
$_SESSION['pga'] = 'done';
$_SESSION['pgb'] = 'done';
$_SESSION['pgC'] = 'done';

OR

am i better setting it as a string then splitting it apart:
$_SESSION['updates'] = 'pga,pgb,pgc';

OR

what if i originally gave each page a value of 0, and after it is run change the value to 1, then move on to the next page.


i have not yet started this, so i dont know if i will have any problems... i just want to figure what my best approach would be
Link to comment
https://forums.phpfreaks.com/topic/29309-loop-through-pages/
Share on other sites

Not sure what it is you are really trying to accomplish. I say that because if you were to state what your reason is for trying to do this, we might be able to suggest a better alternative. Based on the comment "at the bottom of every page it will show a status table." I'm not sure you really know what you are asking. To "jump" to another page with PHP would require the header() function and that requires that you do NOT write anything to the page beforehand.

However, based upon your stated goal, my suggestion would be to create a "processing" page to run all the other files. This way you do not have to keep track of what pages have been run in session variables. You could just keep track onthat single page.

Something like this:

[code]<?php

$pages = array();

include("a.php");
echo "Page a processed"<br>;
$pages[] = "a.php";

include("b.php");
echo "Page b processed<br>";
$pages[] = "b.php";

include("c.php");
echo "Page c processed<br>";
$pages[] = "c.php";
?>[/code]

Of course this would make more sense to run in a loop and/or as a function.
Link to comment
https://forums.phpfreaks.com/topic/29309-loop-through-pages/#findComment-134341
Share on other sites

ok...

pga.php updates database table A
pgb.php updates database table B
etc...

currently i have a link for each file:
<a href='pga.php?dowhat=update'>update A</a>
<a href='pgb.php?dowhat=update'>update B</a>
<a href='pgc.php?dowhat=update'>update C</a>

i click click link a, it runs pga.php, i click link b it runs pgb.php etc...

i want to eliminate all this maual links and have an update 'all' link.

so i click update 'all':
pga.php?dowhat=update - runs

and when it is complete it will show:
pga = updated



then after a few seconds, it will redirect to
pgb.php?dowhat=update

and when this page is complete it will show:
pga = updated
pgb = updated



then after a few seconds, it will redirect to
pgc.php?dowhat=update

and when this page is complete it will show:
pga = updated
pgb = updated
pgc = updated

etc... this will go through about 9 pages

so when "pgi.php?dowhat=update" is complete
the status table will show:
pga = updated
pgb = updated
pgc = updated
pgd = updated
pge = updated
pgf = updated
pgg = updated
pgh = updated
pgi = updated
all tables have been updated!



Link to comment
https://forums.phpfreaks.com/topic/29309-loop-through-pages/#findComment-134370
Share on other sites

Well, you would have to modify ALL of your sub pages to get that functionality becasue PHP cannot display a message and then redirect later. There are a few approaches I can think of.

The easiest approach:
1. Break all of the sub pages into 2 pages. a.php would include all of the HTML for the page and the a_run.php would include all of the processing -plus the message of "pga = updated". On the a.php page you would include the a_run.php in the proper place.
2. Create a master update page that includes all the sub_run pages
Then when the master update page is run you would see a single page with all of the updated messages

A more difficult approach.
1. Modify all of the sub pages to look for a session flag to indicate that you are processin all the pages.
2. If the flag is set you would include some javascript on the page to redirect the pag to the next one after n seconds.

An even more difficult approach, but very cool
1. Create a master processing page that utilizes AJAX
2. The sub pages would need to redone similar to what I described in the first option
3. javascript on the master page would call each sub page one at a time.
4. You could keep a running status on the main page w/o needing to redirect to mutiple pages

For example when processing page a the page could display:

     pga = processing

When it finishes with page a and starts page b you would then see

     pga = updated
     pgb = processing...
Link to comment
https://forums.phpfreaks.com/topic/29309-loop-through-pages/#findComment-134380
Share on other sites

In short, use Ajax if you want this functionality.

In long, create a "processor.php" page that you will pass a page to (pga.php) it will then run that page, and return the values.
You could then have a table auto populate depending on what was returned from processor.php.

mjdamato know's what he's talking about, so heed his advice.

Link to comment
https://forums.phpfreaks.com/topic/29309-loop-through-pages/#findComment-134397
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.