At 03:34 PM 5/23/2002 -0400, Keith C. Ivey wrote:
>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?).

         What I meant by trying to delete from tables that don't have the 
team_id in them was that some of the tables might not have that specific 
team_id in them.  For instance, there is a team, but they do not have a 
home field, so they would not be in the home_field table.
         We have decided to go about it in a different way now, anyway.  We 
have added a new column to each of our tables called "deleted".  We did 
this so it won't mess up past statistics of a team if the team name is deleted.


Steve



---------------------------------------------------------------------
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