473,382 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Update web page from PHP

I have been trying to find a way to update the current web page with data from a PHP program - without success. (searched this forum without success) Looking for some help now.

To explain.. I have a page that calls a php program that will take quite a while to complete, so I want to display on the page the progress of the php. ie Status: Part One.. then when thats done CHANGE 'Part One' to 'Part Two' etc. I do NOT want to keep adding lines to the web page, I want to ALTER the page.

I hope you understand what I mean and can help. I'm thinking that the solution will be a mix of Javascript and PHP.. I'm fairly new to both.
Nov 1 '06 #1
10 10009
4,258 Expert 4TB
If you want to update your page continually from the server, you'll need Ajax. If you just want to do it at the client-side you'll need JS to do that. These is a JS+CSS+DHTML sample (plus source) of a loading bar what you could change to your wishes at progress bar

Ronald :cool:
Nov 1 '06 #2

Thanks for the link.. This though raises a problem .. It says :
:The moveProgressBar() function is called whenever you want to move the progress bar
As I am running a php program, it is from there that I need to call the function, which naturally is in the main page on the site. I have been searching for 'how to call a javascript function from a PHP script' ... without success.. Then if this is possible why can I not set a var or session var in the php and pass that through a function ? Which would of cause answer my query and solve the problem.

Everywhere I go I seem to get a half answer. This tells me to call a function but fails to tell me how to do it. Bit like saying 'If you want to go to the moon build a rocket' Or am I missing something here?
Nov 1 '06 #3
4,258 Expert 4TB
Since you are running the PHP program and that program updates the HTML page at the client, it is all up to you when to display the bar and with what intervals. I don't see the problem. But I have found a couple of PHP classes at phpclasses.org. One of them must satisfy the requirement. They are:

Progress Bar
ProgressBar (not the same as above)
PHProgress Bar

Good luck!

Ronald :cool:
Nov 1 '06 #4
Since you are running the PHP program and that program updates the HTML page at the client, it is all up to you when to display the bar and with what intervals. I don't see the problem.
It doesn't/can't - that is the problem..

to further explain:
User visits site and fills in a form then clicks submit.
form calls the php program which moves files/sets up config files/sets up directories etc: (this takes about 2-3 minutes).

Now I can easilly echo the progress to the browser using echo and flush. Which produces a new page with:-
moving files [run a bit of php]
creating myqsl database [does that]
and so on.

What I want to do is have on the existing page a line/box with
Progress: <some sort of var in here showing the progress the php>. As I'm sure you know if I echo anything from the php it blanks the screen. If I refresh the browser (to re-read a $_SESSION var) it escapes from the php program which terminates.

Hence I thought the solution would need to be a JS/PHP mix . As I said I am fairly new to this and perhaps attempting something too complex. Perhaps I should just settle for a blank screen and echo to it even though that looks hidious
Nov 1 '06 #5
4,258 Expert 4TB
To me that sounds like the perfect Ajax solution to me! I am not a very good Ajax developer (I've only made some small applications), but I am msure this is Ajax.

First, I include a link I found to an article about Ajax file upload progress bar. Look at it.
Secondly, I'll send a note to the moderator of the Ajax/JS forum and ask him to join this conversation. Until then.

Ronald :cool:
Nov 1 '06 #6
1,208 Expert 1GB
Hey guys

I can't think of a way to call a javascript function from php but YOU CAN pass variables from PHP to Javascript.

Now you could do this with ajax but lets try to come up with a less complicated script.

Expand|Select|Wrap|Line Numbers
  1. <?
  2. $progress = "20%"
  3. ?>
  4. <script>
  5. window.onload = updateprogress();
  6. function updateprogress() {
  7. var tmp = "<?=$progress?>";
  8. document.getElementById('progress').innerHTML = tmp+" Completed"
  9. }
  10. </script>
  11. <html>
  12. <body>
  13. <div id="progress"></div>
  14. </body>
  15. </html>

now you could simply do this by the echoing you also said but take it alittle further than that how about this.
Make an inline frame have the php run in this inline frame use this code in the inline frame and have it update the real page with the current progress while having the inline frame hidden. document.parent...
Nov 1 '06 #7
That could be an option, I thought of another solution, which may be of interest to others watching this thread.

Before I explain may I thank you for your pointers and patience.

As I said, the setup.php is called from a form (and I want a var on that page updating)..I have decided to
a) split up the setup.php into the 6 parts that it does
b) design a template page (same as the index page).
c) Used a frameset with a zero top frame (just to hide the urls as progs call progs). Even though I'm not a great fan of frames.

my tmpplate.php has in it..
<td><?php echo $_SESSION['progress'] ?></td>
<!-- and the form fields are ... -->
<td><input name="name" type="text" id="name" value="<?php echo $_SESSION['actName'] ?>" maxlength="30"></td>
$_SESSION['actName'] is created in the first part of the php (start.php)
this means that when the refresh occures the data the user put it is 'replaced'
Hope you follow what I mean. I can put up a demo site if you would like, but you seem very intelligent

Now the form calls start.php.

start.php is
//phpcode .which grabs the form data and passes them into $_SESSION... ending with
$_SESSION['progress']="Creating Folders...";
echo "<META http-equiv='refresh' content='3;URL=http://www.theurl/scripts/part1.php'>";
include ('tmpplate.php');

part1.php is
// this will check and setup folders
// it is called from start.php which said 'Creating Folders'
/// all php code in here
/// to set up the folders
// prep and call part 2
$_SESSION['progress']="Creating Files...";
echo "<META http-equiv='refresh' content='3;URL=http://www.theurl/scripts/part2.php'>";

include ('tmpplate.php');

and so on.. this I know is somewhat messy, but it has the deception of updating the var, and any vars I need throughout the original(now split-up) program are also to be stored in $_SESSION . There is no real sensitive information being stored so I'm not too concerned with storing the data in $_SESSION. part 6 destroys the session and returns to the original index.

Does this make sence ? Have we achieved the impossible?
A new approach to modular programming perhaps :)
Again thank for your patience, guidence, and may I say speed of responce with a newby to php
Nov 1 '06 #8
Ronald, I did look at that AJAX site (Even bookmarked it), also those links to other sites and I thank you for that.

A little background on me, about 20 years ago I was a fairly good (for those times) programmer. However, I got old and technology moved on - passed me by - I know a little bit of a lot of languages (some now dead - or is MASM still used? ). I have rarely and barely programmed for around 7 years. I was asked about a week ago to come up with a solution, by someone I knew from the past (I had a reputation for achieving what was 'not possible') - he sort of challanged me, 6 web design companies he approached told him it could not be done. I had a hunch that php could get into corners that PERL could not. The guts of the program I had done.. all the setting up/moving files/setting up MsSQL databases etc - except this.. I was completely vexed with this problem. With your help and guidence we have achieved a potential solution. Thank you so much.

I will take a look at that AJAX site at some point, but first I need to try to get to understand PHP a little better. (luckily I am verced in perl - to a degree) and the logic of PHP seems like a cross between C and PERL.. It actually seems to be a nice clean language -

But then I am retired from programming now. This stuff does need to be in young brains - us oldies need to let go (just play once in a while - like grandad on the swings in the park)... That's called progress, and long may it go on for without it we would still be naked in caves.

I am very pleased to see that bbs's (forums now) are still such a good source of skilled people, that take the time to help others. I am so greatful for the curtosy and patience shown me on this forum.

Thank you.
Nov 1 '06 #9

Did I not read somewhere that some browsers don't accept/recognise iframes?? would that cause a problem?

Actually I might have read that years ago - just something in the back of my mind about iframes...
Nov 1 '06 #10
4,258 Expert 4TB
Keep up the spirit!!! As an experienced programmer, >37 years, I know it looks all more superficial nowadays, but don't let it get you down! Things like PHP and Ajax, it's just new wine in old bags, the same as it was 40 years ago!! The language may be changed, but the basics are still the same as they have always been.

And indeed, PHP is a child of Perl (maybe C, but that was only 1973), so it isn't that hard to comprehend. Programming isn't that hard, only the language changes, not the basics.

As they say: "old programmers never die".

Ronald :cool:
Nov 2 '06 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Alastair Anderson | last post by:
I have created a very simple form with which I would like to update a single value in a single row of a database as a proof of concept. The relevant parts of the form are a DBWebTextBox (which...
by: Jonathan Upright | last post by:
Greetings to anyone who can help: I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable DataGrid" at the project selector screen. As you may know, it defaults to the Microsoft...
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere I have installed and registered the Sybase...
by: MORALBAROMETER | last post by:
Hi all, I want to update MULTIPLE elements of an HTML page using Ajax. for this reason i my response is an xml document. I want to use XSL at the client side to update these elements. How can i...
by: Evan M. | last post by:
Here's my GridView and my SqlDataSource <asp:GridView ID="ContactHistoryGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ContactHistoryDS" DataKeyNames="JobHistoryID"...
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?...
by: Kristijan Marin | last post by:
Hi, I need to print a report like document. So in report there are many articles and what I need when I get to the end, is to update page numbers on the second page where the Table of Content...
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.