1

My question is fairly simple as I am quite new to dynamic coding languages.

Basically, I want to add a new table row to my table, every 24 hours. The new table row should be added at 00:00 every day and the table data is going to be a pre-set variable which isn't an issue.

HERE IS THE CODE :

<?php

$test="London"

?>



<table width"100%">

  <tr>
    <th width="30%">From</th>
    <th width="30%">Player</th>  
    <th width="40%">Price</th>
  </tr>

  <tr>
    <td><?php echo $test ?></td>
    <td></br></td>    
    <td></br></td>
  </tr>

 

</table>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 4
    If you want it to happen every day at exactly 00:00 you'll need to use a cron job. How you set up the cron job depends on your hosting - http://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php – Styphon Jun 03 '15 at 10:56
  • Are you using any database? – Sougata Bose Jun 03 '15 at 10:59
  • Thank you, I will look into that although it seems quite complex. Surely there is some way to tell a table to add a new – james woski Jun 03 '15 at 11:01
  • @jameswoski there is, but remember that PHP is stateless (unless you provide the state). Each request is essentially fresh. You need to find a place to store what you need (cache, session, DB etc.) and then build what you need each time the page is requested. – Kevin Nagurski Jun 03 '15 at 11:04
  • You can use something simpler to store the data, e.g. a file which has a new row added. But we can't give more help unless we know what sort of storage you want. – M1ke Jun 03 '15 at 11:27

1 Answers1

2

If this is on a Unix-based server you'd need to use a tool called crontab. In a terminal connected to your server type crontab -e and enter:

0 0 * * * php /path/to/script.php

Then save the file. In this example script.php is the file which adds the new row.

The crontab file is structured as follows:

minute hour date month day command

So in the example this occurs at minute 0, hour 0, every date, month and day.

M1ke
  • 6,166
  • 4
  • 32
  • 50