On 23 May 2002, at 12:48, Steve Buehler wrote:

> I am using MySQL with a PHP front end.  Is there a better way to delete 
> from multiple tables than the following?
>       $result=mysql_query("DELETE FROM team WHERE team_id = '$team_id'");
>       $result=mysql_query("DELETE FROM conflicts WHERE team_id = '$team_id'");
>       $result=mysql_query("DELETE FROM home_field WHERE team_id = '$team_id'");

Not really.  You could do something like

foreach ( array('team', 'conflicts', 'home_field') as $table ) {
   $result = mysql_query("DELETE FROM $table WHERE team_id = '$team_id'");
}

but that's the same as far as MySQL is concerned.

> I tried
>       $result=mysql_query("DELETE FROM team,conflicts,home_field WHERE team_id = 
> '$team_id'");
> But of course, that doesn't work.  Or do all of the tables HAVE TO have the 
> $team_id in them for this to work.  The conflicts and home_field tables 
> might not have the $team_id in it.  So I either have to do each table 
> separately or have to come up with a way to delete from multiple tables 
> even if the $team_id is not in the "team_id" column.  Any suggestions?

I'm pretty sure there's nothing resembling that that will work, I don't 
see what you think the advantage would be, and I don't understand what you 
mean about trying to delete from tables that don't have team_id (should 
MySQL magically know which records are associated with an ID that's not 
even in the table?).

-- 
Keith C. Ivey <[EMAIL PROTECTED]>
Tobacco Documents Online
http://tobaccodocuments.org

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to