Re: Delete row in a lookup table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Wow, I actually managed to get this working now. Thanks to Richard and stut I realized I was on the right track but had my code screwed up. Richard your right, a primary key column was silly but was a temporary fix. It allowed me to delete with one column and not have to reference a second. So I dropped the primary key column and have Game_id and Member_id setup as composite key. The trick was to have type twice in the URL and call them both. Thanks for taking time to reply. As simple as that was I wouldnt have done it without a little instruction from yous guys lol.


Here is the code:
The URL:
?action=remove&type=Game&gid={$record->Game_id}&type=Member&mid={$record->Member_id}

The Code:
   case "remove":
     switch ($_GET['type']) {
       case "Game":
		case "Member":
 if (!isset($_GET['do']) || $_GET['do'] != 1) {
?>
 <p align="center" style="color:#FF0000">
   Are you sure you want to delete this <?php
   echo $_GET['type']; ?>?<br>
   <a href="<?php echo $_SERVER['REQUEST_URI']; ?>&do=1">yes</a>
   or <a href="member_view.php">Index</a>
 </p>
<?php
 } else {
   if ($_GET['type'] == "Member") {
     // delete reference to member
   $sql = "DELETE
          FROM xsm_membergames
WHERE Game_id = '" . mysql_real_escape_string((int)$_GET['gid']) . "' AND Member_id = '" . mysql_real_escape_string((int)$_GET['mid']) . "'";
   }
 }


On Sat, August 18, 2007 6:31 pm, nitrox . wrote:
Is it not considered good practice to have a primary key on a lookup
table for a database?
I have 3 tables setup, games, memberleagues and members. The
memberleagues table holds the id of the games table and members table.
The problem I have is that Im not sure how to delete a row from the
memberleagues table without a primary key. If its not considered bad
practice I could add a primary key to the memberleagues table and be
done. Anybody have any tutorials on how to write the php for this?

You can add the primary key, no problem.

However, it might be kind of silly...

For a lookup table, you probably have:

member_id   |    game_id
------------------------
1           | 1
1           | 3
1           | 17
2           | 1
2           | 5




USUALLY you can just have the unique key be the composite key of
member_id, game_id and you just delete "where member_id = $m and
game_id = $g"

The data itself is the key, so to speak, because there can only be one
of each member/game combo, and it's unique all by itself.

Using an extra field for a key is only a "problem" if you have a
zillion members/games to the point where the "extra" space matters on
your hard drive.  In this day and age, you'd have to have a LOT of
members and games for an INT or even BIGINT to make that much
difference on the hard drive.

_________________________________________________________________
Find a local pizza place, movie theater, and more?.then map the best route! http://maps.live.com/default.aspx?v=2&ss=yp.bars~yp.pizza~yp.movie%20theater&cp=42.358996~-71.056691&style=r&lvl=13&tilt=-90&dir=0&alt=-1000&scene=950607&encType=1&FORM=MGAC01

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux