Page 1 of 1

General question about data flow in a php routine

Posted: Sun Feb 12, 2012 4:55 pm
by CaseyC0815
This is my first post on this forum and most likely will not be my last. As a matter of introduction, I am 72 years of age and a retired Systems Analyst/Programmer in the geophysical field. My experience in languages was with Assembler and Fortran IV. Unfortunately I retired before HTML and PHP was around.

I am attempting to modify a php routine that is part of a software package I have running on my website. The routine is written as a combination of php and HTML. The php code does some initialization, includes some code and connects to the data base. The HTML code then displays the welcome page with a couple of menus that get into the rest of the package.

What I would like to do is add some code that would branch out to a "subroutine" (for the lack of proper terminology), wait for the user to click on an option, and then return to the original code after the "subroutine" call.

The problem I have is not knowing the proper terminology. In Fortran I would use a CALL Subroutine (arg1,arg2) which would transfer to the Subroutine and once finished the Subroutine would return control to the calling program at a point past the arguments. Is there something either in PHP or HTML that would accomplish something like this?

Thank you,
Klaus Dieter Cook
Houston, Texas

Re: General question about data flow in a php routine

Posted: Sun Feb 12, 2012 6:22 pm
by Eric!
PHP runs only on the server. So you browse a file that has PHP code and the server executes the code and sends the results to your browser. The user never sees the PHP code. And PHP doesn't wait for anything that a user does. It runs and then it is done. For the browser to interact with the server you have to use javascript. Javascript runs in the browser and can respond to the user's actions, then submits the results to the server (where more PHP code can do something with it).

Re: General question about data flow in a php routine

Posted: Sun Feb 12, 2012 6:26 pm
by rainerpl
Hi

Im not sure i 100% get your problem, but i think what you are trying to do cant be done in php/html, because by the time a web page visitor sees your page and can input anything, php has finished its script and sent out the html code.

You could use sockets for live connection to php script on server side though.


I think you will probably end up splitting your php code into segments that are run depending on what url parameters are sent to your script....which will essentially return to the code where you want it to.

e.g to make a script that asks user 2 numbers and then adds them together, and shows the result you could do something like this(pseudo code). And the user has an option to cancel the task and return to homepage.

Code: Select all

$g  = $_GET['action'];
$v  = $_GET['value1'];
$v2 = $_GET['value2'];

if( $g == "user_entered_numbers"){
   //calculate the answer and show it to the user
}else if($g == "user_pressed_cancel"){
  //redirect browser to new web page...header(location...)
}
else{
 //user hasnt entered any input yet, so ask for numbers
//Here you would generate the HTML code, forms with input options for value1, value2, and cancel
 
}

To take this kind of approach to handle user input, you can reload the page for each interaction, or you can use javascript to handle user input 'behind the scenes'