PHP : echo message for a specified amount of time

前端 未结 6 2147
暗喜
暗喜 2021-01-23 09:34

I want to display a string \"Your status has been posted\" for something around 3 or so seconds than I want it to go away.

As of right now I have a news feed where the u

相关标签:
6条回答
  • 2021-01-23 10:17

    You can't do that with php. Try Javascript instead.

    0 讨论(0)
  • 2021-01-23 10:19

    If sending output to the browser, then you can use javascript to control the time-window you want your text to be visible.

    If using jquery you could use .hide() http://api.jquery.com/hide/

    0 讨论(0)
  • 2021-01-23 10:21

    Unless you go for some weird "100 Continue" approach interleaved before you present your next web page you will need to do this in javascript.

    If this i to display for a period after they first see a webpage then you can have something like a This message will disappear and then add a script which is called from your tag's onLoad action which would (e.g.) sleep for three seconds and then set the content of that div to be empty.

    0 讨论(0)
  • 2021-01-23 10:21

    You cannot achieve this with PHP only; you need JavaScript. Here's a simple example using jQuery: http://jsfiddle.net/4surX/

    0 讨论(0)
  • 2021-01-23 10:26

    You need to add some JavaScript to do this. Here is an outline to get you started:

    <p id="info-message">Your status has been posted</p>
    <script>
      setTimeout(function(){
        document.getElementById('info-message').style.display = 'none';
        /* or
        var item = document.getElementById('info-message')
        item.parentNode.removeChild(item); 
        */
      }, 3000);
    </script>
    

    Also you may want fade-out effects. For that I'd recommend using a library like jQuery or Scriptaculous.

    Useful links:
    https://developer.mozilla.org/en/Window.setTimeout
    http://api.jquery.com/fadeOut/
    http://script.aculo.us/


    Oh, by the way, your script is vulnerable to SQL injection. Always escape your query parameters (or use prepared queries)!

    0 讨论(0)
  • 2021-01-23 10:28

    I'd use AJAX for that. You can assure yourself that the data has been well inserted into the DB, and then show the message with javascript for amount the time you want.

    0 讨论(0)
提交回复
热议问题