PDA

View Full Version : Empty a table?


Poggyuk
Thu 3rd Jul '03, 12:07pm
I've created a small news script for my website.
Everything works fine apart from one part...
I'm trying to make a page that when visited will empty the contents of the table in which my news is stored.

E.g: (my part of the code - adds the table & drops it)

<?php
}
if($step == "table_create"){
?>
<?php
$news = "CREATE TABLE $news_table (
news_id int(10) NOT NULL auto_increment,
un_date int(11) DEFAULT '0' NOT NULL,
news_date varchar(20) NOT NULL,
news_headline varchar(100),
news_text text,
PRIMARY KEY (news_id)
)";
mysql_query($news);
mysql_error();
echo"<p>The news table ($news_table) has been successfully created!</p>";
?>
<?php
}
if($step == "table_empty"){
?>
<?php
$news = "EMPTY TABLE $news_table";
mysql_query($news);
mysql_error();
echo"<p>The news table ($news_table) has been successfully emptied!</p>";
?>
<?php
}
if($step == "table_drop"){
?>
<?php
$news = "DROP TABLE $news_table";
mysql_query($news);
mysql_error();
echo"<p>The news table ($news_table) has been successfully removed!</p>";
?>


I think the command i've used for the empty table step is incorrect (i don't know what the command is). So, could somebody please correct the code for me! ;-)

Thanks in advance.

qxh
Thu 3rd Jul '03, 1:03pm
$news = "TRUNCATE $news_table";