Member Avatar for kirtan_thakkar

If I have a page of 50 lines and I want to run 10-20 lines again if i click on some button..

Is there any way to do this??

Member Avatar for nileshgr

You can create a function for the 10-20 lines.
Then, on the page print a link such that it has an extra HTTP GET attribute at the end.
Like if your URL is page.php then append ?e=1
Now in your PHP script, check for value of $_GET if it is 1, 2, etc. (use switch-case if there are a lot) and call the function you created.

Member Avatar for kirtan_thakkar

You can create a function for the 10-20 lines.
Then, on the page print a link such that it has an extra HTTP GET attribute at the end.
Like if your URL is page.php then append ?e=1
Now in your PHP script, check for value of $_GET if it is 1, 2, etc. (use switch-case if there are a lot) and call the function you created.

Sorry, but i have not understood the logic..
Can you explain..
And how to call function on click to some text or link

Member Avatar for nileshgr
function code_to_be_executed() {
// This is the code to be executed on a special action
// The 10-20 lines
}

// Now the general flow:

echo '<a href=page.php?e=1>....</a>';

if(isset($_GET['e']) and $_GET['e'] == 1) {
code_to_be_executed();
exit; // exit after our special code is executed.
}

// Some first ten lines
// Then call the function to execute the 10-20 lines we had
code_to_be_executed();
Member Avatar for kirtan_thakkar

Thanks for explaining..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.