7 Replies - 558 Views - Last Post: 12 September 2012 - 07:37 AM Rate Topic: -----

#1 umpadnoel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-September 12

php number queue

Posted 08 September 2012 - 09:19 PM

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?
Is This A Good Question/Topic? 0
  • +

Replies To: php number queue

#2 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

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:

<?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

Was This Post Helpful? 0
  • +
  • -

#3 umpadnoel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-September 12

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.
Was This Post Helpful? 0
  • +
  • -

#4 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,205
  • Joined: 19-January 10

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:
if(!isset($_SESSION)) session_start();


This post has been edited by creativecoding: 10 September 2012 - 02:56 PM

Was This Post Helpful? 3
  • +
  • -

#5 umpadnoel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-September 12

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. :)
Was This Post Helpful? 0
  • +
  • -

#6 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: php number queue

Posted 10 September 2012 - 08:45 PM

View Postumpadnoel, 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. :)

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
Was This Post Helpful? 1
  • +
  • -

#7 umpadnoel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-September 12

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?
Was This Post Helpful? 0
  • +
  • -

#8 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

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:
http://somewebsite.com?script.php?foo=bar
Here 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1