Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP countdown to 5 mins after current time?

Options
  • 13-01-2012 4:57pm
    #1
    Registered Users Posts: 9,847 ✭✭✭


    Hi guys,

    I will like to insert a countdown timer of 5 mins after form has been submitted to a php page.

    At the moment when they submit the form they see the date and time they submitted:

    echo date("M d Y H:i", time()) ";

    Any ideas?


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    I'm not really sure what you mean.

    Do you want to display a timer to the end-user which counts down five minutes, or do you want to count down five minutes in the background (e.g. to prevent them submitting a form again for five minutes)?


  • Registered Users Posts: 9,847 ✭✭✭py2006


    seamus wrote: »
    I'm not really sure what you mean.

    Do you want to display a timer to the end-user which counts down five minutes, or do you want to count down five minutes in the background (e.g. to prevent them submitting a form again for five minutes)?

    The former!

    So once the form is submitted, they are taken to the php page which displays what they have filled out and also a countdown starting at 5.00 and going down in secs to 0.

    Is that possible?


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Not in PHP, you'd be looking for a piece of simple javascript to do that. Google for a "countdown timer" or something like that, there will be literally thousands of code samples to download.


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    py2006 wrote: »
    The former!

    So once the form is submitted, they are taken to the php page which displays what they have filled out and also a countdown starting at 5.00 and going down in secs to 0.

    Is that possible?
    What's the count down for?

    I'd consider using javascript for that instead.


  • Registered Users Posts: 9,847 ✭✭✭py2006


    Oh really? I didn't realise that. It doesn't serve any real purpose, just something to add.

    I thought maybe it could be done in php as I am trying to learn it.


  • Advertisement
  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    py2006 wrote: »
    Oh really? I didn't realise that. It doesn't serve any real purpose, just something to add.

    I thought maybe it could be done in php as I am trying to learn it.
    PHP is server side so once it's generated on the server and sent to the browser, PHP can't do anymore. It's up to the client then.


  • Registered Users Posts: 9,847 ✭✭✭py2006


    Webmonkey wrote: »
    PHP is server side so once it's generated on the server and sent to the browser, PHP can't do anymore. It's up to the client then.

    Ah that makes sense.

    Actually while I have your undivided attention. Can you think of any reason why the word Array appears when I get the results of a an array.

    The array works itself no problem. It just has this extra word thrown in haha


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    You are probably just printing the array. You can only print the elements of it.

    [php]
    echo print_r($myArray);
    [/php]

    That would show the contents of the array.

    If you want to do it in a nice way you will have to iterate over the array elements and construct your own way of displaying the data using the elements of the array.


  • Registered Users Posts: 9,847 ✭✭✭py2006


    Webmonkey wrote: »
    You are probably just printing the array. You can only print the elements of it.

    [php]
    echo print_r($myArray);
    [/php]

    That would show the contents of the array.

    If you want to do it in a nice way you will have to iterate over the array elements and construct your own way of displaying the data using the elements of the array.


    Well the following is taking info from 2 checkboxes:
    $pricelist_Books = "3.99";
    
    if(isset($_POST['book']))
     
     {
    	for ($i=0; $i<count($_POST['book']);$i++) {
    		echo "<br />" . $_POST['book'][$i] . "<br /><br />". "<div id=\"prices\">" . "(". "&#8364;". $pricelist_Book . " " . "each" . ")" . "</div>" ."<br /><br />";
    	}
     }
     
     $TotalBookPrice = count($_POST['book']) * $pricelist_Book ;
     echo "Total: " . "&#8364;" . number_format($TotalBookPrice, 2) . " <br /><br />";
    

    It works fine except for the word ARRAY appearing. When neither checkbox is selected then it doesn't show up!


  • Registered Users Posts: 26,574 ✭✭✭✭Creamy Goodness


    use var_dump($var); to see what data type the variable is.

    if it's printing out Array, it's an array and you'll need to go back and debug your code.

    for example: $pricelist_Books = "3.99"; should be $pricelist_Books = 3.99; it's a floating point number and not a string, so when you do $TotalBookPrice = count($_POST) * $pricelist_Book ; you're multiplying a integer (the count) by a string value. not sure if this is your problem but it's not good practice.


  • Advertisement
Advertisement