Re: [PHP] Delete row in a lookup table

2007-08-27 Thread nitrox .
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=removetype=Gamegid={$record-Game_id}type=Membermid={$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:#FF
   Are you sure you want to delete this ?php
   echo $_GET['type']; ??br
   a href=?php echo $_SERVER['REQUEST_URI']; ?do=1yes/a
   or a href=member_view.phpIndex/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=2ss=yp.bars~yp.pizza~yp.movie%20theatercp=42.358996~-71.056691style=rlvl=13tilt=-90dir=0alt=-1000scene=950607encType=1FORM=MGAC01


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



[PHP] How do I delete a composite key?

2007-08-26 Thread nitrox .
Im trying to delete a composite key but cannot figure out the proper format. 
Would somebody tell me where im messing up? I have an url that is supposed 
to send the member id and game id to a delete query. And the delete query is 
supposed to grab the id's based on type.




This is the link:

a 
href=\member_commit.php?action=removetype=Memberid={$record-Member_id}gametype=Gameid={$record-Game_id}\[GAME 
REMOVAL]/a/td\n;




This is the code that recieves the link information:

case remove:
 switch ($_GET['type']) {
   case Member:
 if (!isset($_GET['do']) || $_GET['do'] != 1) {
?
 p align=center style=color:#FF
   Are you sure you want to delete this ?php
   echo $_GET['type']; ??br
   a href=?php echo $_SERVER['REQUEST_URI']; ?do=1yes/a
   or a href=member_view.phpIndex/a
 /p
?php
 } else {
   if ($_GET['type'] == Member) {
 // delete reference to member
   $sql = DELETE
  FROM xsm_membergames
  WHERE Member_id = ' . mysql_real_escape_string((int)$_GET['id']) 
.  .

AND Game_id = ' . mysql_real_escape_string((int)$_GET['id']) . ';
   }
 }

_
Messenger Café — open for fun 24/7. Hot games, cool activities served daily. 
Visit now. http://cafemessenger.com?ocid=TXT_TAGHM_AugHMtagline


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



[PHP] Declare variables in advance question

2007-08-20 Thread nitrox .

I want to declare these variables Game_id and Member_id in advance. Following 
the suggestionfrom one of my books can I do something like this:
 
$expected = array('Game_id', 'Member_id');foreach($expected AS $key) {if ( 
!empty($_POST[$key])) {  ${$key} = $_POST[$key];}else { ${$key} 
= NULL;}}  case addmember:  switch ($_GET['type']) {case 
membergame:  $sql = INSERT INTO xsm_membergames
(Game_id,Member_id)  VALUES 
   (' . mysql_real_escape_string((int)$_POST[Game_id])) . ',
' . mysql_real_escape_string((int)$_POST[Member_id])) . ');  
break;  }  break; 
My concern is did I achieve anything with the code I just added to declare the 
variables? Is it actually being passed to this:  case addmember:  
switch ($_GET['type']) {case membergame:  $sql = INSERT INTO 
xsm_membergames(Game_id,Member_id)  
VALUES(' . 
mysql_real_escape_string((int)$_POST[Game_id]) . ',' . 
mysql_real_escape_string((int)$_POST[Member_id]) . ');  break;  
}  break; 
I did add this and tested it on my server and I didnt recieve any errors. So 
how can I be sure its doing what I intended? 
_
See what you’re getting into…before you go there
http://newlivehotmail.com/?ocid=TXT_TAGHM_migration_HM_viral_preview_0507

[PHP] Delete row in a lookup table

2007-08-18 Thread nitrox .


Hi all,
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?
_
Messenger Café — open for fun 24/7. Hot games, cool activities served daily. 
Visit now.
http://cafemessenger.com?ocid=TXT_TAGLM_AugWLtagline

[PHP] Display paragraphs from a mysql db

2007-06-24 Thread nitrox .

hi all,
 I have a news section on a website that im coding that isnt displaying 
properly. Every paragraph in each news post is being displayed as one big 
paragraph. how can i display my paragraphs in proper form? The field the 
news story is stored in is set as longtext.

here is a link to view.
http://area51.chalkthree.com/index.php?pg=3

the first update shows what im having an issue with. each item in the 
numbered list should be on a seperate line. there are some line breaks as 
well for new paragraphs that arent displaying properly.


here is the code i have:

while($myrow = mysql_fetch_array($newsresults))
 {
 print br;
print $myrow['news_topic'];
print  ;
print $myrow['news_author'];
print;
 print $myrow['topic_date'];
 print br;
 print $myrow['news_message'];
print br\n;
 }

_
Who's that on the Red Carpet? Play  win glamorous prizes. 
http://club.live.com/red_carpet_reveal.aspx?icid=REDCARPET_hotmailtextlink3


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



Re: [PHP] Select record by ID

2007-01-30 Thread nitrox .
Thanks to all who have replied. As you probably have noticed im a total 
novice to php who is trying to achieve big things.


Richard, ive included your suggested code and now my php script is working 
properly. But I dont want to be a php copy/paste newb who has no clue of how 
things are working. If its not too much would you (or anybody) give a brief 
explanation of what this code is doing? Or are there any tutorials online 
that I can read that will educate me on this? Thanks again to all for your 
replies. Ive saved them all for future reference.


atleast this part: $user_id = mysql_real_escape_string((int) 
$_GET['user_id']);


I understand the rest.

?php
include db.php;
$user_id = mysql_real_escape_string((int) $_GET['user_id']);
$query = SELECT user_id, user_name FROM inf_member WHERE user_id=$user_id;
$result = mysql_query($query);
if ( ! $result ) {
die (Could not perform query $query: .mysql_error().\n);
}
while($myrow = mysql_fetch_assoc($result))
 {
echo br;
echo $myrow['user_name'];
echo br;
}
?

_
Invite your Hotmail contacts to join your friends list with Windows Live 
Spaces 
http://clk.atdmt.com/MSN/go/msnnkwsp007001msn/direct/01/?href=http://spaces.live.com/spacesapi.aspx?wx_action=createwx_url=/friends.aspxmkt=en-us


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



[PHP] Select record by ID

2007-01-28 Thread nitrox .
Before I ask my next question I just wanted to thank you all for being in 
this mailing community and sharing your knowledge. Its communitys like this 
that make life easier for all of us. Ok enough with the mushy stuff


Im trying to display one record at a time by ID. Well im getting a blank 
page. Ive looked over my code and tried 20 different ways to get it to work 
to no avail. So any pointers on what Im doing wrong would be great. here is 
the code im working with so far.


?php
include(db.php);

   $result = mysql_query(SELECT * FROM inf_member WHERE 
user_id='$user_id' );

   while($myrow = mysql_fetch_assoc($result))
 {
echo b;
echo $myrow['user_name'];
echo /b;
echo $myrow['rank'];
 echo /b;
echo $myrow['country'];
 echo /b;
echo $myrow['email'];
echo /b;
echo $myrow['quote'];
echo /b;
echo $myrow['config'];
 echo /b;
 echo $myrow['map'];
echo /b;
echo $myrow['gun'];
echo /b;
echo $myrow['brand'];
 echo /b;
 echo $myrow['cpu'];
 echo /b;
echo $myrow['ram'];
echo /b;
echo $myrow['video'];
echo /b;
echo $myrow['sound'];
 echo /b;
 echo $myrow['monitor'];
echo /b;
echo $myrow['mouse'];
echo /b;
echo $myrow['brand'];
 echo /b;

}
?

_
FREE online classifieds from Windows Live Expo – buy and sell with people 
you know 
http://clk.atdmt.com/MSN/go/msnnkwex001001msn/direct/01/?href=http://expo.live.com?s_cid=Hotmail_tagline_12/06


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



Re: [PHP] Select record by ID

2007-01-28 Thread nitrox .
I took the quotes off. I thought that quotes around numbers was wrong also. 
I added the error checking and this is the error:


Could not perform query : You have an error in your SQL syntax; check the 
manual that corresponds to your MySQL server version for the right syntax to 
use near '' at line 1


and this is the code again:

?php
include(db.php);
   $result = mysql_query(SELECT * FROM inf_member WHERE 
user_id=$user_id);

   if ( ! $result ) {
die (Could not perform query $query: .mysql_error().\n);
}

while($myrow = mysql_fetch_assoc($result))
 {
echo b;
echo $myrow['user_name'];
echo /b;
echo $myrow['rank'];
 echo /b;
echo $myrow['country'];
 echo /b;
echo $myrow['email'];
echo /b;
echo $myrow['quote'];
echo /b;
echo $myrow['config'];
 echo /b;
 echo $myrow['map'];
echo /b;
echo $myrow['gun'];
echo /b;
echo $myrow['brand'];
 echo /b;
 echo $myrow['cpu'];
 echo /b;
echo $myrow['ram'];
echo /b;
echo $myrow['video'];
echo /b;
echo $myrow['sound'];
 echo /b;
 echo $myrow['monitor'];
echo /b;
echo $myrow['mouse'];
echo /b;
echo $myrow['brand'];
 echo /b;

}
?

_
Laugh, share and connect with Windows Live Messenger 
http://clk.atdmt.com/MSN/go/msnnkwme002001msn/direct/01/?href=http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-ussource=hmtagline


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



Re: [PHP] multidimensional array problems

2007-01-19 Thread nitrox .
Ive followed your example on grouping. Im still trying to understand all of 
the code but ive made great progess on this with your example. Now I have 
one last issue and this will be solved. Ill remind here what Im trying to 
achieve
I have a table for leagues, lookup table and team roster. There can be 
multiple game types for each game i.e. CoD2 - CTF, CoD2 - SD, CoD2 - TDM. 
If a member is playing CoD2 CTF and CoD2 TDM there should be a table for 
each game and type showing each member playing that game/type. If a member 
is signed up for multiple games/types  he/she should have a name listed 
under each game/type.


Right now my php script is only sorting by game which is putting the same 
person in for each instance of the game instead of sorting through each game 
and then type. So here is my code so far and any help is greatly 
appreciated.


?php
include (db.php);

$memroster = SELECT inf_league.game, inf_league.type, inf_member.user_name, 
inf_member.rank,  .

   inf_member.country, inf_member.email  .
   FROM inf_league  .
   INNER JOIN inf_memberleague ON inf_league.gid = 
inf_memberleague.l_id  .
   INNER JOIN inf_member ON inf_member.user_id = 
inf_memberleague.m_id;

$roster = array();
$memrosterresults = mysql_query($memroster)
or die(mysql_error());
while ($record = mysql_fetch_object($memrosterresults)) {
$roster[$record-game][] = $record;
}
ksort($roster);
foreach ($roster as $game = $records) {
  print table\n;
  print caption{$game}/caption\n;
  print thName/th thRank/th thCountry/th thEmail/th\n;
  foreach ($records as $record) {
print tr\n;
print td{$record-user_name}/td\n;
 print td{$record-rank}/td\n;
 print td{$record-country}/td\n;
 print td{$record-email}/td\n;
 print /tr\n;
   }
print /table\n;
}
?

_
Valentine’s Day -- Shop for gifts that spell L-O-V-E at MSN Shopping 
http://shopping.msn.com/content/shp/?ctId=8323,ptnrid=37,ptnrdata=24095tcode=wlmtagline


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



[PHP] multidimensional array problems

2007-01-13 Thread nitrox doe

hi all,
im very new to php but i think i jumped on the
toughest thing to learn. Im trying to create a
team roster that will show game, game type
and league and then show each member based
on the game type. Ive worked out alot of code
but just cant figure where im going wrong. so
here is my code. Any pointers would be greatly
appreciated.

this is an example of what im trying to do
http://www.chalkthree.com/exampleroster.html

php code
?php
//begin member league table
$memroster = SELECT inf_league.game, inf_league.type, inf_member.user_name, 
inf_member.rank,  .

inf_member.country, inf_member.email  .
FROM inf_league  .
INNER JOIN inf_memberleague ON inf_league.gid = 
inf_memberleague.l_id  .
INNER JOIN inf_member ON inf_member.user_id = 
inf_memberleague.m_id;

$memrosterresults = mysql_query($memroster)
 or die(mysql_error());
 while ($row = mysql_fetch_array($memrosterresults)) {

foreach ($row as $game = $type) {
echo p;
echo $type;
 foreach ($row as $type = $user_name) {
echo $user_name .  -  . $rank .  -  . $country .  -  . $email; 
}

print '/p';
}
}
//end member league table
?








mysql


CREATE TABLE `inf_league` (  `gid` int(11) NOT NULL auto_increment,  `game` 
varchar(255) NOT NULL,  `type` varchar(255) NOT NULL,  `league` varchar(255) 
NOT NULL,  `season` varchar(255) NOT NULL,  PRIMARY KEY  (`gid`)) 
TYPE=MyISAM  AUTO_INCREMENT=4 ;-- -- Dumping data for table `inf_league`-- 
INSERT INTO `inf_league` (`gid`, `game`, `type`, `league`, `season`) VALUES 
(1, 'DF:BHD', 'TKOTH', 'TWL', '2006 1st Quarter');INSERT INTO `inf_league` 
(`gid`, `game`, `type`, `league`, `season`) VALUES (2, 'CoD2', 'CTF', 'TWL', 
'2006 2nd QTR');INSERT INTO `inf_league` (`gid`, `game`, `type`, `league`, 
`season`) VALUES (3, 'CoD2', 'Search  Destroy', 'CAL', '2006 4th QTR');-- 
-- -- Table 
structure for table
`inf_member`-- CREATE TABLE `inf_member` (  `user_id` int(11) NOT NULL 
auto_increment,  `user_level` int(2) NOT NULL default '0',  `list_order` 
int(3) NOT NULL default '0',  `user_name` varchar(100) NOT NULL default '',  
`password` varchar(25) NOT NULL default '',  `email` varchar(100) NOT NULL 
default '',  `country` text NOT NULL,  `game` text,  `rank` varchar(40) 
default NULL,  `qoute` longtext,  `config` int(1) default '0',  `map` 
varchar(100) default '',  `gun` varchar(100) default '',  `brand` 
varchar(100) default '',  `cpu` varchar(20) default '',  `ram` varchar(20) 
default '',  `video` varchar(100) default '',  `sound` varchar(100) default 
'',  `monitor` varchar(100) default '',  `mouse` varchar(100) default '',  
PRIMARY KEY  (`user_id`)) TYPE=MyISAM  AUTO_INCREMENT=3 ;--
-- Dumping data for table `inf_member`-- INSERT INTO `inf_member` 
(`user_id`, `user_level`, `list_order`, `user_name`, `password`, `email`, 
`country`, `game`, `rank`, `qoute`, `config`, `map`, `gun`, `brand`, `cpu`, 
`ram`, `video`, `sound`, `monitor`, `mouse`) VALUES (1, 1, 0, 'nitrox', 
'test', '[EMAIL PROTECTED]', 'United States', 'CoD2', 'Founder', NULL, 0, NULL, 
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);INSERT INTO `inf_member` 
(`user_id`, `user_level`, `list_order`, `user_name`, `password`, `email`, 
`country`, `game`, `rank`, `qoute`, `config`, `map`, `gun`, `brand`, `cpu`, 
`ram`, `video`, `sound`, `monitor`, `mouse`) VALUES (2, 1, 1, 'raze', 
'itsme', '[EMAIL PROTECTED]', 'United States', NULL, 'Leader', NULL, 0, '', 
'', '', '', '', '', '', '', '');-- 
-- -- Table 
structure for table
`inf_memberleague`-- CREATE TABLE `inf_memberleague` (  `l_id` int(4) NOT 
NULL,  `m_id` int(4) NOT NULL) TYPE=MyISAM;-- -- Dumping data for table 
`inf_memberleague`-- INSERT INTO `inf_memberleague` (`l_id`, `m_id`) VALUES 
(1, 2);INSERT INTO `inf_memberleague` (`l_id`, `m_id`) VALUES (1, 1);INSERT 
INTO `inf_memberleague` (`l_id`, `m_id`) VALUES (2, 1);INSERT INTO 
`inf_memberleague` (`l_id`, `m_id`) VALUES (2, 2);


_
Get live scores and news about your team: Add the Live.com Football Page 
www.live.com/?addtemplate=footballicid=T001MSN30A0701


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