good day! I just want to ask if anyone has the idea on how to show the next number on queue on another php page after a certain user clicked a button from different page without leaving the page where the button exist?
php number queue
Page 1 of 17 Replies - 369 Views - Last Post: 12 September 2012 - 07:37 AM
Replies To: php number queue
#2
Re: php number queue
Posted 09 September 2012 - 01:17 AM
Good morning, umpadnoel, and welcome to Dream.In.Code.
You could use sessions or cookies.
For example, one the page displaying the numbers:
On the page where the numbers are set, for example, a search page that's been paginated:
This does mean you'll have the refresh the first page displaying the number to see the updated result, or you could use ajax to fetch the result.
Hope this helps
~huzi
You could use sessions or cookies.
For example, one the page displaying the numbers:
<?php @session_start(); $number = isset($_SESSION['number']) ? intval($_SESSION['number']) : 1; //if the number has been set, retrieve it, else use one. echo $number; //display the number ?>
On the page where the numbers are set, for example, a search page that's been paginated:
<?php @session_start(); $page = isset($_GET['page']) && !empty($_GET['page']) ? $_GET['page'] : 1; $_SESSION['number'] = $page; ?>
This does mean you'll have the refresh the first page displaying the number to see the updated result, or you could use ajax to fetch the result.
Hope this helps
~huzi
This post has been edited by huzi8t9: 09 September 2012 - 05:16 AM
#3
Re: php number queue
Posted 09 September 2012 - 07:34 PM
Thank you for your reply, i really appreciate it, you just helped me realized that it really might be impossible to call an ajax function on the display page from the user page where the button is clicked.
#4
Re: php number queue
Posted 09 September 2012 - 09:47 PM
@huzi:
Do not use the error suppression symbol (@). Not only is it slow, it makes debugging a nightmare. Good code should emit no notices, no warnings, no errors.
Also don't use intval, use type casting. Instead of intval($var), use (int)$var. Type casting is much faster (300%-600%, source).
EDIT:
I should have added this on earlier, but if you are using the '@' on session_start worried about a "headers already sent" error, you should look into design patterns like MVC. If you're worried about "session already started, use this:
Do not use the error suppression symbol (@). Not only is it slow, it makes debugging a nightmare. Good code should emit no notices, no warnings, no errors.
Also don't use intval, use type casting. Instead of intval($var), use (int)$var. Type casting is much faster (300%-600%, source).
EDIT:
I should have added this on earlier, but if you are using the '@' on session_start worried about a "headers already sent" error, you should look into design patterns like MVC. If you're worried about "session already started, use this:
if(!isset($_SESSION)) session_start();
This post has been edited by creativecoding: 10 September 2012 - 02:56 PM
#5
Re: php number queue
Posted 10 September 2012 - 08:34 PM
Thanks guys.
but i'm still curious if it's possible to call functions and pass perimeters to function in page2 from page 1 without leaving page 1?
using autorefresh on page 2 is the number 1 option but i'm thinking there might be another way of doing it.
using autorefresh on page 2 is the number 1 option but i'm thinking there might be another way of doing it.
#6
Re: php number queue
Posted 10 September 2012 - 08:45 PM
umpadnoel, on 10 September 2012 - 11:34 PM, said:
Thanks guys.
but i'm still curious if it's possible to call functions and pass perimeters to function in page2 from page 1 without leaving page 1?
using autorefresh on page 2 is the number 1 option but i'm thinking there might be another way of doing it.
using autorefresh on page 2 is the number 1 option but i'm thinking there might be another way of doing it.
It is possible but not with PHP alone. You would have to use Ajax, which falls under Javascript, to do it. Basically Ajax will send a request (GET, POST...etc) to the PHP script asynchronously. Have a look at this tutorial on executing Ajax calls: Performing GET and POST requests using Ajax
#7
Re: php number queue
Posted 11 September 2012 - 06:22 PM
@codeprada thanks! yes i've been thinking ajax but the thing is, is it possible to call and pass perimeters to ajax on the second page? and display the output on the same page when you're on page 1?
#8
Re: php number queue
Posted 12 September 2012 - 07:37 AM
An Ajax call is just sending a request to the server. In other words you can pass values through GET, POST, DELETE and PUT requests. If you wanted to pass values through GET you simply set the Ajax URL to something like:
To be even more realistic we can store it for further use.
http://somewebsite.com?script.php?foo=barHere we'll be passing the value bar. To get the value from your PHP script it will be simply
$foo = $_GET['foo'];
To be even more realistic we can store it for further use.
session_start(); $_SESSION['foo'] = $_GET['foo'];
This post has been edited by codeprada: 12 September 2012 - 07:39 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|