how can i run this when the page loads?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevrelland
Forum Commoner
Posts: 73
Joined: Mon Jan 08, 2007 7:41 am

how can i run this when the page loads?

Post 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
Last edited by kevrelland on Mon May 19, 2008 4:51 am, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: can this be simplified?

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: can this be simplified?

Post 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'");
}
 
kevrelland
Forum Commoner
Posts: 73
Joined: Mon Jan 08, 2007 7:41 am

Re: can this be simplified?

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: can this be simplified?

Post 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.
Post Reply