removing "echo"'d text?
I want to create a single PHP file that in reality looks like multiple pages ( I suppose this is a good way to say it )
For example I have a page that has
echo "Please wait while this page loads";
then I want to clear away that presented text on the next specified command, for example
some sort of code here that clears away the [echo "Please wait while this page loads";];
echo "Page loaded";
code that waits two seconds;
some sort of code here that clears away the [echo "Page loaded";];
The rest of the websites code here....
I cant seem to find any way to clear this sort of thing, or make it look like a new page(I don't care if I have to esentially create a new page each time I just want it all in one php file).. How on earth is this done?
Clearing echo'd text... help please total newb
Moderator: General Moderators
Re: Clearing echo'd text... help please total newb
With JavaScript. You can't "un-echo" text - once it's sent it's too late to change your mind.
Method #1: display the message and hide it when the data starts getting echoed.
Method #2: display the message, do some processing, and redirect the user when it's all ready.
These two methods require you to use flush when you output something: in general, when you echo/print something it does not go immediately to the browser.
Method #3: AJAX. Too lazy to post code for that, but basically you query the server every X seconds, checking if everything is ready. If so you redirect to that page, otherwise you wait and try again.
Then there's the no-JavaScript method #4, much like #3. Tell the browser to reload the page every X seconds (make sure the page is very lightweight so it loads quickly) and when the data is ready you do a redirect from PHP.
The Refresh could go in the <head> like
There are a million other ways too.
Method #1: display the message and hide it when the data starts getting echoed.
Code: Select all
<div id="loading"><p>Loading...</p></div>
... time spent processing ...
<script type="text/javascript">
document.getElementById("loading").style.display = "none";
</script>
real data followsCode: Select all
same div as before
... time spent processing ...
<script type="text/javascript">
document.location.href = "/path/to/file.php?id=123456";
</script>Method #3: AJAX. Too lazy to post code for that, but basically you query the server every X seconds, checking if everything is ready. If so you redirect to that page, otherwise you wait and try again.
Then there's the no-JavaScript method #4, much like #3. Tell the browser to reload the page every X seconds (make sure the page is very lightweight so it loads quickly) and when the data is ready you do a redirect from PHP.
Code: Select all
// if the data is ready
header("Location: /path/to/file.php?id=123456");
// if not
header("Refresh: X"); // X=number of secondsCode: Select all
<meta http-equiv="Refresh" content="X">Re: Clearing echo'd text... help please total newb
Thanks guys I think I have located what I'm looking for and I am experimenting with option #1 as I am a total newb and "/path/to/file.php?id=123456"; make no sense to me yet, I understand that the ?id=#### is a way to tell my php page that theres a variable of some sort being passed to it but thats all beyond me at the moment LOL but option #1 seems to solve the issue at the moment, thanks alot!