Removing DB Entires
Moderator: General Moderators
Removing DB Entires
Hi
I have a table, with a number on entries that must be manually deleted from the database.
What is the script for removing rows (entries) from a mysql table?
I have a table, with a number on entries that must be manually deleted from the database.
What is the script for removing rows (entries) from a mysql table?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
this is generally done like so..
1. you have have a unique ID on each row.. this can be accomplished by having a column (ID) set to autoincrement
2. You loop through your results, and create the links, adding the unique id on the link
and then on delete.php you would have something like this
for more information and syntax on mysql visit
http://dev.mysql.com/doc/mysql/en/index.html
1. you have have a unique ID on each row.. this can be accomplished by having a column (ID) set to autoincrement
2. You loop through your results, and create the links, adding the unique id on the link
Code: Select all
$result = mysql_query("SELECT * FROM `rows`") or die(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
echo '<a href="delete.php?id='.$rowї'id'].'">Delete ME</a>";
}Code: Select all
if (!empty($_GETї'id']))
{
mysql_query("DELETE FROM `rows` WHERE `id` = '".$_GETї'id'].' LIMIT 1") or die(mysql_error());
}http://dev.mysql.com/doc/mysql/en/index.html
Likely, as you are connecting to the database prior to retrieving/deleting data.volkan wrote:Thanks for the reply.
Do i need to include a dbconnent.php?
Additionally, you do not crearly (for me
volkan wrote:Hi
I am trying to remove all the entires on the table!
That link doesn't contain the script for it.
What is the line?
Code: Select all
mysql_query('truncate table table_name');Hi,
Sorry, i admit im impatient.
So....
Is this corrrect??:
REMOVE.php
and
delete.php
also,
what is a good book to learn about php + mysql insterface?
Sorry, i admit im impatient.
So....
Is this corrrect??:
REMOVE.php
Code: Select all
<?php
$result = mysql_query("SELECT * FROM `rows`") or die(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
echo '<a href="delete.php">Delete ME</a>";
}
?>delete.php
Code: Select all
<?php
include("DBCONNECT.php");
{
mysql_query('truncate table table_name') or die(mysql_error());
}
?>
{
mysql_query('truncate table table_name') or die(mysql_error());
}
?>what is a good book to learn about php + mysql insterface?
Meaning, if you issue this command, you will empty the entire table. Links containing 'Delete ME' as in your REMOVE.php file are obsolete.MySQL Manual wrote:13.1.9. TRUNCATE Syntax
TRUNCATE TABLE tbl_name
TRUNCATE TABLE empties a table completely. Logically, this is equivalent to a DELETE statement that deletes all rows, but there are practical differences under some circumstances.
You can asweel link to/visit the delete.php directly ( http://www.example.com/delete.php ) and the data will be gone...
The delete.php only needs the truncate table query one time aswell.
i got ya,
so accessing delete.php
which contains:
that only deletes the entires right? no the sql structure.
so accessing delete.php
which contains:
Code: Select all
<?php
include("DBCONNECT.php");
{
mysql_query('truncate table table_name') or die(mysql_error());
}
?>