|
-
Sep 28th, 2006, 01:57 PM
#1
Thread Starter
Addicted Member
How to pick live stats php ajax php
I want to show user live result of some calculations.
It includes solving 10 different problems and i want to show user thru ajax that problem number (1,2,3..) is being solved so that user feel easy.
I have coded ajax file and everything is ok and working.
But problem is that i am not able to find the way that how to put ajax file in middle of first php (from where after submitting form calculations started) file and second php (where all results will be shown) file.
Please help me that i can redirect user to ajax file after submission of form from first php and then after calculations are completed it would be redirected to second php file (from middle ajax file).
I will be thankful to you.
-
Sep 28th, 2006, 02:14 PM
#2
Re: How to pick live stats php ajax php
uhh, I'm not totally understanding what you want, so.. from what I understand you want the form to go to the AJAX file and then the ajax file to redirect to the second PHP page when it's complete?
so, make your first PHP page have a <form> action="ajax.php" and add another form to the AJAX file that has an action="secondphppage.php," then after the calculations are done make hidden input fields that pass the information (using <input type="hidden">), and then add a submit button and make sure it works. this isn't totally automated, though. But, make sure it works.. and then you could possibly use JavaScript to automatically submit the form on the AJAX page.
If this isn't what you wanted try to explain what you want a bit better.
Also, I don't have much of any experience with AJAX, so this is mostly a shot in the dark. If you give me more information (if it's something I need to know, that is) then I can help you better.
-
Sep 28th, 2006, 02:25 PM
#3
Thread Starter
Addicted Member
Re: How to pick live stats php ajax php
yes its exactly what i want to do. 
but little confusion in my mind is that when as you are saying on first php file i redirect to ajax. then how calculations would start ?
Actually what i need is to start calculations and then using ajax to display live progress and when everything is done then redirect user to complete info page.
-
Sep 28th, 2006, 02:27 PM
#4
Thread Starter
Addicted Member
Re: How to pick live stats php ajax php
when user would be on ajax file there must be running first php file for calculations. purpose of ajax file is to show progress of calculations which is being done by first php file.
-
Sep 28th, 2006, 02:40 PM
#5
Thread Starter
Addicted Member
Re: How to pick live stats php ajax php
actually first php file must keep on runnin on backend.
Key problem is how to display ajax file contents to user while first file is running on bachend.
-
Sep 28th, 2006, 03:16 PM
#6
Re: How to pick live stats php ajax php
..? if the first file is just a form then what would be the point of it to continue running? if you submit to the AJAX file through a form (like <form method="post" action="ajax.php">) then use $_POST to get your variables and do the calculations in ajax..
you're going to have to post the code for the stuff you're doing if you want more help, because I'm having a hard time trying to figure out what you're doing..
-
Sep 29th, 2006, 02:03 AM
#7
Thread Starter
Addicted Member
Re: How to pick live stats php ajax php
you can say there are total 4 files.
file 1 (html) == with form
file 2 (php) == all calculations to be peformed by
file 3 (ajax) == to display live progress
file 4 (php) == to present all results
-
Sep 29th, 2006, 02:54 AM
#8
Re: How to pick live stats php ajax php
.. it seems to me like you're making it harder than it has to be. can't you just combine all four into the same file? or at least, combine 2 and 3. If you're having trouble putting them together, or getting it to work in the sequence you want it to, then post some code so I can try to point you in the right direction. It's hard to help you write PHP if I don't know what you're working with.
-
Sep 29th, 2006, 03:15 AM
#9
Thread Starter
Addicted Member
Re: How to pick live stats php ajax php
code will not help it will become even more confusing.
I have given all info above.
Problem is how to make ajax file working properly and keeping file 2 (php) running on backend.
Problem is like multithreading that at a time both file should work.
-
Sep 29th, 2006, 03:59 AM
#10
Re: How to pick live stats php ajax php
Unless you give me some stuff I can try out on my local webserver to play around with, I can't really help you out. Sorry, but solving the problem isn't as easy (at least to me?) as you're making it out to be. If you want, PM me a zip file of the PHP/HTML files and I will take a look and let you know.
-
Sep 29th, 2006, 05:55 AM
#11
Re: How to pick live stats php ajax php
I think you're mistunderstanding how AJAX works. I've only skimmed this thread, but there's a lot of confusion here.
The point of AJAX is that the user never reloads the page in the first place.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 29th, 2006, 06:23 AM
#12
Thread Starter
Addicted Member
Re: How to pick live stats php ajax php
you are right CornedBee.
As AJAX is not need to load page while showing info from server.
That's why i want to use AJAX (middle page) for displaying results of calculations ( calculations that are performed by first php file and when all calculations will be done then it i want to send user to page where all info will be presented.
HTML (form) -> PHP (calc started) AND user redirected to AJAX page -> HTML (all calc results displayed)
-
Sep 29th, 2006, 06:27 AM
#13
Re: How to pick live stats php ajax php
But that's the wrong approach, when you're doing AJAX. Oh, and it's not really possible either.
But to give you a right approach, a need a more complete description of what effect you're trying to achieve.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 29th, 2006, 06:48 AM
#14
Thread Starter
Addicted Member
Re: How to pick live stats php ajax php
Purpose is very simple just for example
There is code of calculating tables of 1 to 100 in file1.php
Now user submit form on main.html to calculate tables.
As code for calculating tables is in file1.php so it must be called.
Here comes need of AJAX ... its purpose is to display user that currently table of (1,2,3.. 100) is being calculated. And its all the purpose of my use of AJAX.
And there after when table of 100 will be generated i want to redirect user from AJAX viewing page to result.php where all results would be displayed at once.
Is it clear to you ?
-
Sep 29th, 2006, 07:12 AM
#15
Re: How to pick live stats php ajax php
Yeah. AJAX is the wrong tool. Just keep the connection to the calculating PHP script alive, write update status messages as you go, and use flush() to make sure they reach the client. You might also want to disable script timeout during the execution.
When you're done, write a message saying so, give a link that leads to the result display page, and write a JS snippet that attempts automatic redirect. (The link is in case JS is disabled.)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 29th, 2006, 07:17 AM
#16
Re: How to pick live stats php ajax php
 Originally Posted by CornedBee
The point of AJAX is that the user never reloads the page in the first place.
From anything I've read, that's what I understood about it.. but I've never used it or tried it out, so I wasn't exactly sure how it was called or used.. or anything! @_@. I hadn't even heard of it until a few weeks ago.. hehe.
-
Sep 29th, 2006, 07:36 AM
#17
Thread Starter
Addicted Member
Re: How to pick live stats php ajax php
 Originally Posted by CornedBee
Yeah. AJAX is the wrong tool. Just keep the connection to the calculating PHP script alive, write update status messages as you go, and use flush() to make sure they reach the client. You might also want to disable script timeout during the execution.
When you're done, write a message saying so, give a link that leads to the result display page, and write a JS snippet that attempts automatic redirect. (The link is in case JS is disabled.)
I think now i am on the track because you now exactly know what i want to do. 
I am not big fan of AJAX main purpose was to keep user informed about calculations progress.
Now how it can be done in php?
because in AJAX it was easy to write inner html of "progress" in below div.
<div id="progress"></div>
and on every instance info keeps on updating in same div layer but how it would be done in php ?
so that i can update info in same div by ob_flush() ?
-
Sep 29th, 2006, 08:15 AM
#18
Re: How to pick live stats php ajax php
I'd do it like this:
Code:
<!-- Some introductory HTML here. -->
<div id="progress">
<?php
flush();
// Insert code here to prevent script timeout. I forgot what, search this forum.
for($i = 0; $i < $numTables; ++$i) {
calculateTable($i);
echo "Table ".($i + 1)." complete.<br>\n";
flush();
}
?>
</div>
<p>Calculations completed. You will be forwarded to the results in a moment.</p>
<p>If the forward doesn't work, please <a href="results.php?resultid=<?php echo $resultid; ?>">manually advance to the results</a>.</p>
<script type="text/javascript">window.location.href = 'results.php?resultid=<?php echo $resultid; ?>';</script>
<!-- HTML outro -->
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 29th, 2006, 09:48 AM
#19
Thread Starter
Addicted Member
Re: How to pick live stats php ajax php
CornedBee
It would work like that
Output:
Table 1 complete.
Table 2 complete.
Table 3 complete.
Table 4 complete.
.
.
.
Table 100 complete.
It would write 100 lines.
----------------
I want that every time only number should be updated like
Output:
Table 1 complete.
and then
Output:
Table 2 complete.
and then
Output:
Table 3 complete.
.
.
.
Output:
Table 100 complete.
It will look acceptable for user and me. that only in 1 line changes are displayed .. that's what ajax can do.
Is there any solution to display it in only 1 line ?
-
Sep 29th, 2006, 09:57 AM
#20
Re: How to pick live stats php ajax php
Yeah, but it's considerably more complicated, and it does require AJAX. I'd advise you to learn the basics of AJAX before attempting it.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 29th, 2006, 10:21 AM
#21
Thread Starter
Addicted Member
Re: How to pick live stats php ajax php
Hmmm
I am currently using include function to write html of ajax file but unfortunately its not working but when i run it independentally it works.
ob_start();
include ("ajax.php");
ob_flush();
technically as code of ajax.php is flushed it should start executing javascripts necessary for showing progress are not running (i think).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|