Re: multidimensional array problems
| From: | Larry Garfield | Date: | Sun, 14 Jan 2007 03:51:08 +0000 |
| Subject: | Re: multidimensional array problems | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247058@lists.php.net to get a copy of this message | ||
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 ¨€¯ó°Î&Õ�
> =7i�6inf_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 r¹ÒTT n�
>
Áñ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@me.com', '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, rË
> pÆ
ãÚ³hÃ$»mouse) VALUES (2, 1, 1, 'raze',
> 'itsme', 'itsyou@itsyou.com', '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 ‚1û:½W
> òëLÂæoinf_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@garfieldtech.com 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