Re: multidimensional array problems

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

 



Copying back to the list...

Actually, I'd suggest doing a PHP-side grouping.  See this article for 
details:

http://www.garfieldtech.com/blog/php-group-by

On Saturday 13 January 2007 10:50 pm, nitrox . wrote:
> I hope this is returning to the mail list so all can read.
> Thanks for the reply Larry, i appreciate your time spent to reply to me. If
> i print the way your showing it prints for every instance. Im trying to
> create a team roster like the following url shows:
> http://www.chalkthree.com/exampleroster.html
>
> I have 3 tables in my db, league table, lookup table and member table. Do
> you think it would be better possably to do seperate querys and then match
> them in php? would that be possable the given the setup i have?
>
> >From: Larry Garfield <larry@xxxxxxxxxxxxxxxx>
> >To: php-general@xxxxxxxxxxxxx
> >Subject: Re:  multidimensional array problems
> >Date: Sat, 13 Jan 2007 21:51:08 -0600
> >
> >It's better to just leave the record as an array and read it that way.
> >
> >while ($row = mysql_fetch_assoc($result)) {
> >print "<tr><td>{$row['game']}</td> <td>{$row['type']}</td></tr>\n";
> >}
> >
> >And so on.  You're not actually dealing with a multi-dimensional array
> > yet; $result is an object from which you are extracting data records as
> > one-dimensional associative arrays.
> >
> >On Saturday 13 January 2007 7:40 pm, nitrox doe wrote:
> > > 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', 'itsme@xxxxxx', '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', 'itsyou@xxxxxxxxxx', '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=football&icid=T001MSN30A0701
> >
> >--
> >Larry Garfield			AIM: LOLG42
> >larry@xxxxxxxxxxxxxxxx		ICQ: 6817012
> >
> >"If nature has made any one thing less susceptible than all others of
> >exclusive property, it is the action of the thinking power called an idea,
> >which an individual may exclusively possess as long as he keeps it to
> >himself; but the moment it is divulged, it forces itself into the
> >possession
> >of every one, and the receiver cannot dispossess himself of it."  --
> > Thomas Jefferson
> >
> >--
> >PHP General Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php
>
> _________________________________________________________________
> From photos to predictions, The MSN Entertainment Guide to Golden Globes
> has it all. http://tv.msn.com/tv/globes2007/?icid=nctagline1

-- 
Larry Garfield			AIM: LOLG42
larry@xxxxxxxxxxxxxxxx		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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