954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

delete statement php/sql

hello is this how u do a delete query from mysql table i need to delete it depending on id number so if user enters id 10 it needs to delete the all the rows that have id 10 from any table which has that id.. thanks

$query = "DELETE
tbl_name[.*] [, tbl_name[.*]]
FROM tom, ron, chris, bert
WHERE id ='$value'";
$result = mysql_query($query);

aran87
Light Poster
42 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

hello is this how u do a delete query from mysql table i need to delete it depending on id number so if user enters id 10 it needs to delete the all the rows that have id 10 from any table which has that id.. thanks

$query = "DELETE tbl_name[.*] [, tbl_name[.*]] FROM tom, ron, chris, bert WHERE id ='$value'"; $result = mysql_query($query);


using your data, assuming 'tom', 'ron', 'chris' and 'bert' are table names.

DELETE tom.*, ron.*, chris.*, bert.*
FROM tom, ron, chris, bert
WHERE id = '$value';


Sam

helraizer
Light Poster
48 posts since Apr 2008
Reputation Points: 11
Solved Threads: 3
 

In syntax "markup" anything in angle brackets, < >, is a required field, anything inside brackets [ ], is optional. So DELETE FROM <table> means that youmust have something where it says , ie., DELETE FROM someTable .

That said the query format is

DELETE FROM <table > [, table [...]] [WHERE <col> = <value> [LIMIT <offset>[,<number>]

Meaning that you can do DELETE FROM someTable, someSecondTable WHERE row = 3 LIMIT 0,2 Which would delete everything from someTable and someSecondTable where row is equal to 3. Or I could simply do, DELETE FROM someTable WHERE row = 3

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You