Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-12-2005, 10:42 PM Clearing a page
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
Hello again peoples!

Again, Ive come accross a problem while doing my daily PHP coding. Well, its not so much a problem, but itd be nice to have a solution.

In a short and sweet version of my question - is there anyway to clear - or refresh if you like - the outputted stuff on the page when I run my function?

I have a function called error(), which is basically used for all my errors. When I run it id like it to be able to clear anything on the page then output the error.

So for example if I do

PHP Code:
echo("Ehllo!");
echo(
"<br /> ....Hello?");
error("Bah!"); 
It wont print:

Quote:
Ehllo!
....Hello?
Error! The error returned was Bah!
But only print
Quote:
Error! The error returned was Bah!


By Clear I mean everything (if possible) including the <html><head> etc. as I can re-output all that in my error function if needed.





Thanks yee!
AxEh!
AxE is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-13-2005, 03:07 AM
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
Maybe you can simple redirect usrer on error page,

header("Location:error.php");

and print out whatever you want.
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 09-13-2005, 05:03 PM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
Hi, thanks for the reply


That would work, but I have my set out like:

PHP Code:
<html>
<head>

</head>
<body>
<tables n stuff>
<? PHP TO INCLUDE OTHER PAGES ?>
</tables>
</body>
</html>
I use one page to navigate my site by including the others. Using headers would just return a Headers Already Sent error...
AxE is offline
Reply With Quote
View Public Profile
 
Old 09-14-2005, 12:56 AM
eburza's Avatar
Super Talker

Posts: 122
Name: Antonio Magdic
Location: Zagreb, Croatia
Trades: 0
try to write
@error(); ....

it wont display ...
__________________

Please login or register to view this content. Registration is FREE
eburza is offline
Reply With Quote
View Public Profile Visit eburza's homepage!
 
Old 09-14-2005, 01:19 AM
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
Maybe this can help you.

<?
$inc = include("someFile.php");
echo $inc;
?>
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 09-14-2005, 05:06 AM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
The problem is that by having that layout on your page (all php in one place) you are missing out on php power, as shivaji suggested you should be aiming at performing the action and if it doesn’t work then output the error. You cannot redirect with php after the page has loaded, as all contact with the server is lost. This would have to be done with JavaScript.
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Old 09-15-2005, 01:27 AM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
Quote:
try to write
@error(); ....

it wont display ...
Its not that I do not want it to display the error, but I want it to display the error, and just the error. I want it to clear the rest of the page before showing the error.

Quote:
Maybe this can help you.

<?
$inc = include("someFile.php");
echo $inc;
?>
Again, even if I put my error function in a different page and included it, it wouldnt do what I wanted. I want it to clear the page...

Quote:
The problem is that by having that layout on your page (all php in one place) you are missing out on php power,
Its the way I code. I dont use echo, or store my text in variables, its because I just close the PHP tags and then write my text, so I dont lose out on the syntax highlighting while writing large chunks of HTML. This means that if I make it output for example, the header for a table, then it outputs an error itll not only have my error, but half a chunk of table too.

Quote:
as shivaji suggested you should be aiming at performing the action and if it doesn’t work then output the error.
I split things up alot. I try to give the user as much information as I can. The main problem with my error function is that I check every single query or mysql_fetch_array or page include and error if something goes wrong, so I can get an error randomly in the middle of the page if a query goes wrong for some reason.

Quote:
You cannot redirect with php after the page has loaded, as all contact with the server is lost. This would have to be done with JavaScript.
Im not trying to redirect, im trying to clear the page.

Out of curiosity: Would the output buffer functions (ob_start() etc.) be able to help me in any way? They sound relevant but im not sure exactly what they do.
AxE is offline
Reply With Quote
View Public Profile
 
Old 09-15-2005, 02:35 PM
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
Quote:
I split things up alot. I try to give the user as much information as I can. The main problem with my error function is that I check every single query or mysql_fetch_array or page include and error if something goes wrong, so I can get an error randomly in the middle of the page if a query goes wrong for some reason.
I am very poor in English and maybe I didnt understand you. But, if I good understand, you want clear page in moment when your php script detect an error and print out only your error message on blank, empty page ?
Am I right?
Are you working with HTML form?
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 09-15-2005, 02:48 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Output buffering is probably exactly what you need. It basically holds back all the HTML output on the server until you are ready, at which point it gets sent all in one go. This way you can generate your page, test for success and then send the whole page, or just the error message.
I've not used it myself but it seems to be right for the job. The PHP manual page on it is here.

I'm thinking if you call ob_start() at the top of your script, ob_end_flush() at the bottom, and then in between if you detect your error condition you just call ob_end_clean() to kill the page so far and then output the error using echo and die.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)

Last edited by 0beron; 09-15-2005 at 02:51 PM..
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 09-20-2005, 07:06 AM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
You sir, are a God. Nay! An Angel! With a magic wand! And flappy wings!



It all worked as you said it would, thank you!
AxE is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Clearing a page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.65402 seconds with 12 queries