Page 1 of 1

how can i run this when the page loads?

Posted: Thu May 15, 2008 5:30 am
by kevrelland
i want to run this when the page loads, how can i do it?

Code: Select all

 
<?php
mysql_query("DELETE FROM fixtures");
mysql_query("DELETE FROM highest_alley");
mysql_query("DELETE FROM player_scores");
mysql_query("DELETE FROM player_averages");
mysql_query("DELETE FROM results");
mysql_query("DELETE FROM tables");
mysql_query("DELETE FROM team_averages");
mysql_query("DELETE FROM trophy_leaders");
?>
Cheers
Kevin

Re: can this be simplified?

Posted: Thu May 15, 2008 5:43 am
by onion2k
No. Besides, you're deleting stuff, you don't want to use any shortcuts on something that important.

If you're concerned about speed then TRUNCATE is faster than DELETE FROM.

Re: can this be simplified?

Posted: Thu May 15, 2008 5:44 am
by aceconcepts
You could use an array:

Code: Select all

 
$tableArray=array("fixtures", "highest_alley", "player_scores", "player_averages", "results", "tables", "team_averages", "trophy_leaders");
 
foreach($tableArray as $table)
{
   $delSql=mysql_query("DELETE FROM '$table'");
}
 

Re: can this be simplified?

Posted: Mon May 19, 2008 3:48 am
by kevrelland
how can i make this run when the page loads cause at the moment i need to refresh the page to get it to work?
Cheers

Re: can this be simplified?

Posted: Mon May 19, 2008 1:26 pm
by califdon
kevrelland wrote:how can i make this run when the page loads cause at the moment i need to refresh the page to get it to work?
Cheers
PHP runs on the server. By the time the page loads in the browser, there is no more PHP.

You could do it with an asynchronous call, like Ajax.