poe Posted December 3, 2006 Share Posted December 3, 2006 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';ORam i better setting it as a string then splitting it apart:$_SESSION['updates'] = 'pga,pgb,pgc';ORwhat 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 More sharing options...
projectshifter Posted December 3, 2006 Share Posted December 3, 2006 It really doesn't matter how you store that a page has been run as long as you are capable of keeping track of it. I'd say if you want them to all run, either transfer through them with header('Location: b.php'); or just include them all in one file. Link to comment https://forums.phpfreaks.com/topic/29309-loop-through-pages/#findComment-134330 Share on other sites More sharing options...
Psycho Posted December 3, 2006 Share Posted December 3, 2006 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 More sharing options...
poe Posted December 3, 2006 Author Share Posted December 3, 2006 ok...pga.php updates database table Apgb.php updates database table Betc...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 - runsand when it is complete it will show:pga = updatedthen after a few seconds, it will redirect to pgb.php?dowhat=updateand when this page is complete it will show:pga = updatedpgb = updatedthen after a few seconds, it will redirect to pgc.php?dowhat=updateand when this page is complete it will show:pga = updatedpgb = updatedpgc = updatedetc... this will go through about 9 pagesso when "pgi.php?dowhat=update" is completethe status table will show:pga = updatedpgb = updatedpgc = updatedpgd = updatedpge = updatedpgf = updatedpgg = updatedpgh = updatedpgi = updatedall tables have been updated! Link to comment https://forums.phpfreaks.com/topic/29309-loop-through-pages/#findComment-134370 Share on other sites More sharing options...
Psycho Posted December 3, 2006 Share Posted December 3, 2006 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 pagesThen when the master update page is run you would see a single page with all of the updated messagesA 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 cool1. Create a master processing page that utilizes AJAX2. The sub pages would need to redone similar to what I described in the first option3. 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 pagesFor example when processing page a the page could display: pga = processingWhen 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 More sharing options...
keeB Posted December 3, 2006 Share Posted December 3, 2006 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.