Re: [PHP] multidimensional array problems

2007-01-19 Thread Larry Garfield
It's actually quite simple.  You simply add another layer of grouping.  
General case:

$result = mysql_query("SELECT a, b, c, d FROM foo ORDER BY a, b, c");
while ($record = mysql_fetch_object($result)) {
  $roster[$record->a][$record->b][] = $record;
}

ksort($roster);

foreach ($roster as $a => $bfield) {
  print $a;
  ksort($bfield);
  foreach ($bfield as $b => $record) {
print "$a: $b";
print_r($record);
  }
}

Add real output syntax to taste.


On Friday 19 January 2007 4:33 pm, nitrox . wrote:
> 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 - S&D, 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.
>
>  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 "\n";
>print "{$game}\n";
>print "Name Rank Country Email\n";
>foreach ($records as $record) {
>  print "\n";
>  print "{$record->user_name}\n";
>   print "{$record->rank}\n";
>   print "{$record->country}\n";
>   print "{$record->email}\n";
>   print "\n";
> }
> print "\n";
> }
> ?>

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   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



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 - S&D, 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.


$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 "\n";
  print "{$game}\n";
  print "Name Rank Country Email\n";
  foreach ($records as $record) {
print "\n";
print "{$record->user_name}\n";
 print "{$record->rank}\n";
 print "{$record->country}\n";
 print "{$record->email}\n";
 print "\n";
   }
print "\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=24095&tcode=wlmtagline


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



Re: [PHP] multidimensional array problems

2007-01-13 Thread Jim Lucas

Give this a go

$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());

$currentType = FALSE;
echo "\n";
while ( $row = mysql_fetch_assoc($memrosterresults) ) {
   if ( $row['type'] != $currentType ) {
   if ( $currentType !== FALSE ) {
   echo "\n";
   echo "\n";
   }
   echo "{$row['type']}\n";
   $currentType = $row['type'];
   }
   echo "{$row['user_name']} - {$row['rank']} - {$row['country']} - 
{$row['email']}\n";

}
echo "\n";
//end member league table
?>

This is untested, but it should give you the results you are looking for.

Jim Lucas

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
$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 "";
echo "$type";
 foreach ($row as $type => $user_name) {
echo "$user_name" . " - " . "$rank" . " - " . "$country" . " - " . 
"$email"; }

print '';
}
}
//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`) VALU

Re: [PHP] multidimensional array problems

2007-01-13 Thread Larry Garfield
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 <[EMAIL PROTECTED]>
> >To: php-general@lists.php.net
> >Subject: Re: [PHP] 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 "{$row['game']} {$row['type']}\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
> > >  > > //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 "";
> > > echo "$type";
> > >   foreach ($row as $type => $user_name) {
> > > echo "$user_name" . " - " . "$rank" . " - " . "$country" . " - " .
> > > "$email"; }
> > > print '';
> > > }
> > > }
> > > //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', 
>

Re: [PHP] multidimensional array problems

2007-01-13 Thread Larry Garfield
It's better to just leave the record as an array and read it that way.

while ($row = mysql_fetch_assoc($result)) {
print "{$row['game']} {$row['type']}\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
>  //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 "";
> echo "$type";
>   foreach ($row as $type => $user_name) {
> echo "$user_name" . " - " . "$rank" . " - " . "$country" . " - " .
> "$email"; }
> print '';
> }
> }
> //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=football&icid=T001MSN30A0701

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thi

[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
$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 "";
echo "$type";
 foreach ($row as $type => $user_name) {
echo "$user_name" . " - " . "$rank" . " - " . "$country" . " - " . "$email"; 
}

print '';
}
}
//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=football&icid=T001MSN30A0701


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



Re: [PHP] multidimensional array sort

2005-03-14 Thread Ashley M. Kirchner
Leif Gregory wrote:
http://us3.php.net/manual/en/function.array-multisort.php
   I did go through that, but I can't get it to work and I'm almost 
willing to bet it's because of the way the array is built.  For example, 
the example on that page says that I should be able to do a sort on 
$ar[0] and $ar[1], however in my array both of those return 0.  In fact, 
when I do this:

 echo "items in array: " . count($data) . "";
 for ($i = 0; $i < count($data); $i++) {
   echo "data[$i]: " . count($data[$i]) . "";
 }

   I get:
 items in array: 2
 data[0]: 0
 data[1]: 0

   When I do a print_r($data), I get:
 Array
   (
  [John] => Array
 (
[KIRASH] => Array
  (
 [0] => 050311_18.00.59__KIRASH.zip
 [1] => 050311_18.10.20__KIRASH.zip
  )
[MCCROY] => Array
  (
 [0] => 050312_20.52.28__MCCROY.zip
  )
 )
  [Ron] => Array
 (
[EMBROR] => Array
  (
 [0] => 050314_15.47.56__EMBROR.zip
  )
 )
   )
   S, I'm at a loss here.  I think I need to create the array 
differently for it to work.

--
H | I haven't lost my mind; it's backed up on tape somewhere.
 +
 Ashley M. Kirchner    .   303.442.6410 x130
 IT Director / SysAdmin / WebSmith . 800.441.3873 x130
 Photo Craft Imaging   . 3550 Arapahoe Ave. #6
 http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A. 

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


Re: [PHP] multidimensional array sort

2005-03-14 Thread Leif Gregory
Hello Ashley,

Monday, March 14, 2005, 12:12:19 PM, you wrote:
A> I need to do a sort on the whole thing in such a way that:
A>a) all the Dir#'s are in ascending order, and
A>b) all the User#'s are in ascending order with each Dir#, and
A>b) all the File#'s are also in ascending order within each User#


http://us3.php.net/manual/en/function.array-multisort.php


It's funny, I was in the exact same boat this morning with regards to
generating a sign-in sheet for a class where I had pulled out all the
students into a multi-dimensional array and needing to sort them by
last name ascending. I was just about to delve into array-multisort
when it dawned on me that this would be the perfect opportunity for a
table join. So, I learned how to do a MySQL join (my first) a few
hours ago. It works great! Much less headache too.

$sqlRegisteredStudents="SELECT s.id, s.firstName, s.lastName, s.phone, s.email, 
s.divisionOrFacility, s.supervisorName " .
"FROM " . $tbl_registrations . " r JOIN " . 
$tbl_students . " s " .
"ON r.studentId = s.id " .
"WHERE courseId='" . $_POST['courseID'] . "' " .
"ORDER BY s.lastName ASC";

-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

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



[PHP] multidimensional array sort

2005-03-14 Thread Ashley M. Kirchner
   I have a multidimensional array that's built as follows (it's pretty 
much a directory tree):

Array (
 [Dir1] => Array (
 [User1] => Array (
 [0] => File1
 [1] => File2
 )
 [User2] => Array {
 [0] => File1
 [1] => File2
 [2] => File3
 }
 )
 [Dir2] => Array (
 [User1] => Array (
 [0] => File1
 [1] => File2
 [2] => File3
 [3] => File4
 )
 [User2] => Array {
 [0] => File1
 }
 )
)
   I need to do a sort on the whole thing in such a way that:
  a) all the Dir#'s are in ascending order, and
  b) all the User#'s are in ascending order with each Dir#, and
  b) all the File#'s are also in ascending order within each User#
   I don't suppose there's an easy way to do this, other than doing it 
in several steps, is there?  Is there even a way to JUST sort the Dir#'s 
(and the rest gets done at a later stage in the script)?

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


[PHP] Multidimensional Array advice from a newbie

2004-06-12 Thread grahama
Hi :)
I am creating an XML file out of a mysql query with nested arrays.
Currently I can get 1 element and 1 child with a properly formatted XML 
file with the below script .

My question is: How do  I  add 3 to 4 more child elements to the below 
'playlist' array ?
Currently ,I have one parent 'Artist' and one child 'english' ...
I need to add more child elements to the 'Artist' array like urlPath, 
spanish, biography, etc

My addled thoughts...
So, would the multidimensional array be like:
$playlist[   [$artist [ ]   ][$media[ ]  ]	[$mediaElement]  
]?

for the  'trackName' child:
$playlist [ "Artist 1" ] [ "Track 1" ]   [ "trackName" ]
or for 'urlPath' child :
$playlist [ "Artist 1" ] [ "Track 1" ] [ "urlPath" ]
Do I have to add another dimension to the 'playlist' array? Do I need 
another  foreach loop ?
Is there an easier more efficient way to do this?
Be nice to spell out the schema in some way in the script...in case you 
need to add more levels...like a 'subCategory'

I am a bit new to this so any help would be greatly appretiated  
head is spinning a bit


$sql = 'SELECT artist.artist_name, media.english, media.path ';
$sql .= 'FROM media, artist ';
$sql .= 'WHERE artist.artist_id = media.artist_id LIMIT 0, 30 ';
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$playlist[$row['artist_name']] [] = $row['english'];
//would like to add more children here...
}
$xml = "\n";
foreach ($playlist as $artist => $media)
{
$num_media = count($media);
$xml .= "\n";   

$xml .= "\t\n";   
$xml .= "\t\t".$artist."\n";
$xml .= "\t\n";  

$xml .= "\t\n";
foreach ($media as $mediaVal)
{
$xml .= "\t\t\n";
$xml .= "\t\t\t".$mediaVal."\n";
///add more children
///add more children
$xml .= "\t\t\n";   

}

$xml .= "\t\n";   
$xml .= "\n";  
}
$xml .= "\n";
print $xml
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Multidimensional Array manipluation...

2003-01-02 Thread Dhaval Desai
Hi,

Well, I will be having something like this:

$se5f2254321s65s32s65[] will hold various valus like jan_1,jan-2,jan_3,jan_4 
etc and then jan_1 will hold 1, jan_2=2,, jan_3=1 etc etc...

Depending on certain conditions, I want to increment the values of certain 
values in the array...like...
for($i=0; $i<=count($se5f2254321s65s32s65); $i++)
  {
  $se5f2254321s65s32s65[$i]["jan_1"] = 1
  }
I want to increment it with 1 and so on for the various other values


Thanx

Best Regards,
Dhaval





From: Chris Shiflett <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: Dhaval Desai <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED]
Subject: Re: [PHP] Multidimensional Array manipluation...
Date: Thu, 2 Jan 2003 09:30:43 -0800 (PST)

> >$test["0"]["hey"] = 1;
> >$test["1"]["hi"] = 2;
> >$test["2"]["hello"] = 3;
>
> I want to update $test["0"]["hey"] and set it as 1+1;

If you just want to increment the value:

$test["0"]["hey"]++;

> Also is there any idea on how can we count() the values
> in a multi dimensional arrays...

The function array_count_values() might give you what you
want. What are you wanting to count exactly?

A good reference for you online is:

http://www.php.net/manual/en/ref.array.php

Chris



_
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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



Re: [PHP] Multidimensional Array manipluation...

2003-01-02 Thread Chris Shiflett
> >$test["0"]["hey"] = 1;
> >$test["1"]["hi"] = 2;
> >$test["2"]["hello"] = 3;
> 
> I want to update $test["0"]["hey"] and set it as 1+1;

If you just want to increment the value:

$test["0"]["hey"]++;

> Also is there any idea on how can we count() the values
> in a multi dimensional arrays...

The function array_count_values() might give you what you
want. What are you wanting to count exactly?

A good reference for you online is:

http://www.php.net/manual/en/ref.array.php

Chris

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




Re: [PHP] Multidimensional Array manipluation...

2003-01-02 Thread Dhaval Desai
Hi,

Thanx for the reply, well but what about the second part or my mail..

I want to use in_array("value", $array);
and if found, I want to update the value of that variable...


$test["0"]["hey"] = 1;
$test["1"]["hi"] = 2;
$test["2"]["hello"] = 3;


I want to update $test["0"]["hey"] and set it as 1+1;
I think it's possible using splice()m I don't know exactly how to use it 
with Multi Dimensional arrays

Also is there any idea on how can we count() the values in a multi 
dimensional arrays...


Thanx




From: Chris Shiflett <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: Dhaval Desai <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
Subject: Re: [PHP] Multidimensional Array manipluation...
Date: Thu, 2 Jan 2003 09:04:27 -0800 (PST)

--- Dhaval Desai <[EMAIL PROTECTED]> wrote:
> $test[0] = "hey";
> $test[1] = "hi";
> $test[2] = "hello";
>
> Now I want to hold various values in $test[0]["hey"] =
> "1" and $test[1]["hi"] = "2" and $test[2]["hello"] = "3"

Try this instead:

$test["0"]["hey"] = 1;
$test["1"]["hi"] = 2;
$test["2"]["hello"] = 3;

Also, remember that you can often learn these types of
things with trial and error by using the print_r()
function:

print_r($test);

Chris



_
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail


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



Re: [PHP] Multidimensional Array manipluation...

2003-01-02 Thread Chris Shiflett
--- Dhaval Desai <[EMAIL PROTECTED]> wrote:
> $test[0] = "hey";
> $test[1] = "hi";
> $test[2] = "hello";
> 
> Now I want to hold various values in $test[0]["hey"] =
> "1" and $test[1]["hi"] = "2" and $test[2]["hello"] = "3"

Try this instead:

$test["0"]["hey"] = 1;
$test["1"]["hi"] = 2;
$test["2"]["hello"] = 3;

Also, remember that you can often learn these types of
things with trial and error by using the print_r()
function:

print_r($test);

Chris

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




[PHP] Multidimensional Array manipluation...

2003-01-02 Thread Dhaval Desai
Hello ppl,

I was trying to do something with an array...I guess you could see what I 
mean from the code below:


$test[0] = "hey";
$test[1] = "hi";
$test[2] = "hello";

Now I want to hold various values in $test[0]["hey"] = "1" and 
$test[1]["hi"] = "2" and $test[2]["hello"] = "3"
and then I want to use the function let's say in_array("hey", $test) and if 
it's found in the array I want to update the value in that array from 1 to 
1+1 or anything...

All of the above would be done dynamically from database, the above is just 
to get the Logic..I hope it's possible...I am keeping my fingers crossed...

Thank You
Best Regards,
Dhaval


_
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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



[PHP] Multidimensional array

2002-11-28 Thread Mako Shark
(Thanks to all who've replied about the streaming
audio. Haven't had a chance to respond or anything
yet.)

Here is a problem I'm having similar to somethnig
someone just posted, but not quite the same. I'm not
too experienced with the intricacies and
complications of arrays, but I have a bunch of fields
like this for a magazine organizer (best way to put
it, I guess):

$issuenumber[]
$issueheadline[]
$issuewriters[]
$issuemonth[]
$issueyear[]
$issuedescription[]
among other fields.

I would like to store this all in one multidimensional
array, like
$issue->number[]
$issue->headline[]
etc.

What is the syntax? I'm bumbling around right now.
Also, if I sort() the array by number, would the rest
of the fields be properly sorted? I assume so, but
don't want to find out the hard way that it doesn't.

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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




Re: [PHP] multidimensional array

2002-04-19 Thread Miguel Cruz

On Fri, 19 Apr 2002, Rodrigo Peres wrote:
> In order to avoid many left joins I took an aproach that I didn't know
> if it's good, but I couldn't figure out another way. If my cliente has
> 10 phone numbers I buld an array, serialize it and store in database, so
> I didn't have to create another table.

What do you have against left joins?

miguel


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




[PHP] multidimensional array

2002-04-19 Thread Rodrigo Peres

Hi list,

In order to avoid many left joins I took an aproach that I didn't know
if it's good, but I couldn't figure out another way. If my cliente has
10 phone numbers I buld an array, serialize it and store in database, so
I didn't have to create another table. The problem is now I need to
migrate the data to this format, how can I select the multiple data and
put in multidimensional array at runtime to store again. for example I
need to put all fileds with graduation and all fields with discipline
with equal id in array named school serialize it and after insert in
another table.

Thank's

Rodrigo



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




[PHP] multidimensional array

2002-04-19 Thread Rodrigo Peres

Hi list,

In order to avoid many left joins I took an aproach that I didn't know 
if it's good, but I couldn't figure out another way. If my cliente has 
10 phone numbers I buld an array, serialize it and store in database, so 
I didn't have to create another table. The problem is now I need to 
migrate the data to this format, how can I select the multiple data and 
put in multidimensional array at runtime to store again. for example I 
need to put all fileds with graduation and all fields with discipline 
with equal id in array named school serialize it and after insert in 
another table.

Thank's

Rodrigo


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




RE: [PHP] Multidimensional array construction

2001-12-07 Thread Tim Ward

I haven't seen the rest of this thread so this may be irrelevant ... but

foreach($array as $key=>$value)
{   $array[$key] = "fred";
}

... alters an array while traversing it. Your case seems more complicated
but I would have thought nesting foreaches in this way would allow you to
access the original element.


foreach($array as $key1=>$value1)
{   foreach($array as $key2=>$value2)
{   $array[$key1][$key2] = "fred";
}
}

Tim
http://www.chessish.com <http://www.chessish.com> 


--
From:  Darren Gamble [SMTP:[EMAIL PROTECTED]]
Sent:  04 December 2001 15:22
To:  PHP List; 'Mike Eheler'
Subject:  RE: [PHP] Multidimensional array construction

Good day,

Thanks to all who replied.

This isn't quite what I needed, though.  I _have_ the array (or
delimited
list would do, too).  What I need to do is _CREATE_ the array
element
$myarray['foo']['bar']['green']['apple'] and set it to some value.
Actually
traversing said array isn't hard, as you pointed out.

foreach() doesn't work, as it just uses a copy of the original
array.  I
think there might be some way to use variable references, but I
haven't
gotten one to work yet.

Any other suggestions?


Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948


-Original Message-
From: Mike Eheler [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 03, 2001 5:30 PM
    To: Martin Towell
Cc: 'Darren Gamble'; PHP List
Subject: Re: [PHP] Multidimensional array construction


I did something like this recently. Here's how I did it:

$some_value1 = 'Hello World';
$myarray['foo']['bar']['green']['apple'] = $some_value1;

function get_opt($arr, $keys,$sep=':') {
$var = $arr;
$tmp = split($sep,$keys);
foreach ($tmp as $k => $v) {
$var = $var[$v];
}
if (isset($var)) return $var;
return '';
}

echo get_opt($myarray, 'foo:bar:green:apple');

It needs refining, but it should do the job. That's entirely from 
memory, mind you.. it should work, though.

Mike

Martin Towell wrote:

>I was thinking that you could use a "pointer to var", eg:
>$var = 'myarray["foo"]["bar"]["red"]["apple"]';
>// this would obviously be created dynamically, hard coded for
testing
>$$var = $some_value1;
>echo $myarray["foo"]["bar"]["red"]["apple"];
>but when I tried it, it didn't work :(
>looks like eval() to the rescue...
>
>-Original Message-
>From: Darren Gamble [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, December 04, 2001 10:37 AM
>To: PHP List
>Subject: [PHP] Multidimensional array construction
>
>
>Here's a question for the list:
>
>I have a two-dimensional array; essentially a list of arrays.  Each
element
>(an array) can have any number of elements.  As a small example:
>
>(
>  ( "foo" , "bar" , "red" , "apple" ),
>  ( "foo" , "bar" , "red" , "car"),
>  ( "foo" , "green" )
>)
>
>I would like to traverse this array and place all of the data into
another
>multidimensional array.  The following statements illustrate how
I'd like
to
>do this from the example:
>
>$myarray["foo"]["bar"]["red"]["apple"] = $some_value1;
>$myarray["foo"]["bar"]["red"]["car"]   = $some_value2;
>$myarray["foo"]["green"]   = $some_value3;
>
>Is there any way to easily do this in PHP?  I could "cheat" and use
eval(),
>but there is probably a better way.  I have thought of using each()
or
>references, but nothing has come to mind so far. 
>
>Any ideas?  Should I just use eval() ?
>
>
>Darren Gamble
>Planner, Regional Services
>Shaw Cablesystems GP
>630 - 3rd Avenue SW
>Calgary, Alberta, Canada
>T2P 4L4
>(403) 781-4948
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Multidimensional array construction

2001-12-04 Thread Darren Gamble

Good day,

Thanks to all who replied.

This isn't quite what I needed, though.  I _have_ the array (or delimited
list would do, too).  What I need to do is _CREATE_ the array element
$myarray['foo']['bar']['green']['apple'] and set it to some value.  Actually
traversing said array isn't hard, as you pointed out.

foreach() doesn't work, as it just uses a copy of the original array.  I
think there might be some way to use variable references, but I haven't
gotten one to work yet.

Any other suggestions?


Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948


-Original Message-
From: Mike Eheler [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 03, 2001 5:30 PM
To: Martin Towell
Cc: 'Darren Gamble'; PHP List
Subject: Re: [PHP] Multidimensional array construction


I did something like this recently. Here's how I did it:

$some_value1 = 'Hello World';
$myarray['foo']['bar']['green']['apple'] = $some_value1;

function get_opt($arr, $keys,$sep=':') {
$var = $arr;
$tmp = split($sep,$keys);
foreach ($tmp as $k => $v) {
$var = $var[$v];
}
if (isset($var)) return $var;
return '';
}

echo get_opt($myarray, 'foo:bar:green:apple');

It needs refining, but it should do the job. That's entirely from 
memory, mind you.. it should work, though.

Mike

Martin Towell wrote:

>I was thinking that you could use a "pointer to var", eg:
>$var = 'myarray["foo"]["bar"]["red"]["apple"]';
>// this would obviously be created dynamically, hard coded for testing
>$$var = $some_value1;
>echo $myarray["foo"]["bar"]["red"]["apple"];
>but when I tried it, it didn't work :(
>looks like eval() to the rescue...
>
>-Original Message-
>From: Darren Gamble [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, December 04, 2001 10:37 AM
>To: PHP List
>Subject: [PHP] Multidimensional array construction
>
>
>Here's a question for the list:
>
>I have a two-dimensional array; essentially a list of arrays.  Each element
>(an array) can have any number of elements.  As a small example:
>
>(
>  ( "foo" , "bar" , "red" , "apple" ),
>  ( "foo" , "bar" , "red" , "car"),
>  ( "foo" , "green" )
>)
>
>I would like to traverse this array and place all of the data into another
>multidimensional array.  The following statements illustrate how I'd like
to
>do this from the example:
>
>$myarray["foo"]["bar"]["red"]["apple"] = $some_value1;
>$myarray["foo"]["bar"]["red"]["car"]   = $some_value2;
>$myarray["foo"]["green"]   = $some_value3;
>
>Is there any way to easily do this in PHP?  I could "cheat" and use eval(),
>but there is probably a better way.  I have thought of using each() or
>references, but nothing has come to mind so far. 
>
>Any ideas?  Should I just use eval() ?
>
>
>Darren Gamble
>Planner, Regional Services
>Shaw Cablesystems GP
>630 - 3rd Avenue SW
>Calgary, Alberta, Canada
>T2P 4L4
>(403) 781-4948
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Multidimensional array construction

2001-12-03 Thread Mike Eheler

I did something like this recently. Here's how I did it:

$some_value1 = 'Hello World';
$myarray['foo']['bar']['green']['apple'] = $some_value1;

function get_opt($arr, $keys,$sep=':') {
$var = $arr;
$tmp = split($sep,$keys);
foreach ($tmp as $k => $v) {
$var = $var[$v];
}
if (isset($var)) return $var;
return '';
}

echo get_opt($myarray, 'foo:bar:green:apple');

It needs refining, but it should do the job. That's entirely from 
memory, mind you.. it should work, though.

Mike

Martin Towell wrote:

>I was thinking that you could use a "pointer to var", eg:
>$var = 'myarray["foo"]["bar"]["red"]["apple"]';
>// this would obviously be created dynamically, hard coded for testing
>$$var = $some_value1;
>echo $myarray["foo"]["bar"]["red"]["apple"];
>but when I tried it, it didn't work :(
>looks like eval() to the rescue...
>
>-Original Message-
>From: Darren Gamble [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, December 04, 2001 10:37 AM
>To: PHP List
>Subject: [PHP] Multidimensional array construction
>
>
>Here's a question for the list:
>
>I have a two-dimensional array; essentially a list of arrays.  Each element
>(an array) can have any number of elements.  As a small example:
>
>(
>  ( "foo" , "bar" , "red" , "apple" ),
>  ( "foo" , "bar" , "red" , "car"),
>  ( "foo" , "green" )
>)
>
>I would like to traverse this array and place all of the data into another
>multidimensional array.  The following statements illustrate how I'd like to
>do this from the example:
>
>$myarray["foo"]["bar"]["red"]["apple"] = $some_value1;
>$myarray["foo"]["bar"]["red"]["car"]   = $some_value2;
>$myarray["foo"]["green"]   = $some_value3;
>
>Is there any way to easily do this in PHP?  I could "cheat" and use eval(),
>but there is probably a better way.  I have thought of using each() or
>references, but nothing has come to mind so far. 
>
>Any ideas?  Should I just use eval() ?
>
>
>Darren Gamble
>Planner, Regional Services
>Shaw Cablesystems GP
>630 - 3rd Avenue SW
>Calgary, Alberta, Canada
>T2P 4L4
>(403) 781-4948
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Multidimensional array construction

2001-12-03 Thread Jim


oops. That's not correct. I wish it was though! ;)


>This might be interesting ...
>
>The function extract() allows you to extract all values from an 
>array and prefix them with a specified string. What I didn't know 
>until just a second ago was that you can supply a function as a 
>string, so ...
>
>$my_array = array("a","b","c","d",array("a","b","c","d"));
>
>$i = 1;
>
>extract($my_array,EXTR_PREFIX_ALL,"SOMEVAL".$i++);
>
>print "";
>
>print $SOMEVAL_1;
>print $SOMEVAL_2;
>print $SOMEVAL_3;
>print $SOMEVAL_4;
>print $SOMEVAL_5;
>
>print "";
>
>... will produce:
>
>a
>b
>c
>d
>[Array]
>
>Which is cool. Not quite what you wanted, but maybe you could run with it.
>
>Jim
>
>
>>
>>-Original Message-
>>From: Darren Gamble [mailto:[EMAIL PROTECTED]]
>>Sent: Tuesday, December 04, 2001 10:37 AM
>>To: PHP List
>>Subject: [PHP] Multidimensional array construction
>>
>>
>>Here's a question for the list:
>>
>>I have a two-dimensional array; essentially a list of arrays.  Each element
>>(an array) can have any number of elements.  As a small example:
>>
>>(
>>   ( "foo" , "bar" , "red" , "apple" ),
>>   ( "foo" , "bar" , "red" , "car"),
>>   ( "foo" , "green" )
>>)
>>
>>I would like to traverse this array and place all of the data into another
>>multidimensional array.  The following statements illustrate how I'd like to
>>do this from the example:
>>
>>$myarray["foo"]["bar"]["red"]["apple"] = $some_value1;
>>$myarray["foo"]["bar"]["red"]["car"]   = $some_value2;
>>$myarray["foo"]["green"]   = $some_value3;
>>
>>Is there any way to easily do this in PHP?  I could "cheat" and use eval(),
>>but there is probably a better way.  I have thought of using each() or
>>references, but nothing has come to mind so far.
>>
>>Any ideas?  Should I just use eval() ?
>>
>>
>>Darren Gamble
>>Planner, Regional Services
>>Shaw Cablesystems GP
>>630 - 3rd Avenue SW
>>Calgary, Alberta, Canada
>>T2P 4L4
>>(403) 781-4948
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>--
>Jim Musil
>-
>Multimedia Programmer
>Nettmedia
>-
>212-629-0004
>[EMAIL PROTECTED]
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
Jim Musil
-
Multimedia Programmer
Nettmedia
-
212-629-0004
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Multidimensional array construction

2001-12-03 Thread Jim

This might be interesting ...

The function extract() allows you to extract all values from an array 
and prefix them with a specified string. What I didn't know until 
just a second ago was that you can supply a function as a string, so 
...

$my_array = array("a","b","c","d",array("a","b","c","d"));

$i = 1;

extract($my_array,EXTR_PREFIX_ALL,"SOMEVAL".$i++);

print "";

print $SOMEVAL_1;
print $SOMEVAL_2;
print $SOMEVAL_3;
print $SOMEVAL_4;
print $SOMEVAL_5;

print "";

... will produce:

a
b
c
d
[Array]

Which is cool. Not quite what you wanted, but maybe you could run with it.

Jim



>
>-Original Message-----
>From: Darren Gamble [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, December 04, 2001 10:37 AM
>To: PHP List
>Subject: [PHP] Multidimensional array construction
>
>
>Here's a question for the list:
>
>I have a two-dimensional array; essentially a list of arrays.  Each element
>(an array) can have any number of elements.  As a small example:
>
>(
>   ( "foo" , "bar" , "red" , "apple" ),
>   ( "foo" , "bar" , "red" , "car"),
>   ( "foo" , "green" )
>)
>
>I would like to traverse this array and place all of the data into another
>multidimensional array.  The following statements illustrate how I'd like to
>do this from the example:
>
>$myarray["foo"]["bar"]["red"]["apple"] = $some_value1;
>$myarray["foo"]["bar"]["red"]["car"]   = $some_value2;
>$myarray["foo"]["green"]   = $some_value3;
>
>Is there any way to easily do this in PHP?  I could "cheat" and use eval(),
>but there is probably a better way.  I have thought of using each() or
>references, but nothing has come to mind so far.
>
>Any ideas?  Should I just use eval() ?
>
>
>Darren Gamble
>Planner, Regional Services
>Shaw Cablesystems GP
>630 - 3rd Avenue SW
>Calgary, Alberta, Canada
>T2P 4L4
>(403) 781-4948
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
Jim Musil
-
Multimedia Programmer
Nettmedia
-
212-629-0004
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Multidimensional array construction

2001-12-03 Thread Martin Towell

I was thinking that you could use a "pointer to var", eg:
$var = 'myarray["foo"]["bar"]["red"]["apple"]';
// this would obviously be created dynamically, hard coded for testing
$$var = $some_value1;
echo $myarray["foo"]["bar"]["red"]["apple"];
but when I tried it, it didn't work :(
looks like eval() to the rescue...

-Original Message-
From: Darren Gamble [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 04, 2001 10:37 AM
To: PHP List
Subject: [PHP] Multidimensional array construction


Here's a question for the list:

I have a two-dimensional array; essentially a list of arrays.  Each element
(an array) can have any number of elements.  As a small example:

(
  ( "foo" , "bar" , "red" , "apple" ),
  ( "foo" , "bar" , "red" , "car"),
  ( "foo" , "green" )
)

I would like to traverse this array and place all of the data into another
multidimensional array.  The following statements illustrate how I'd like to
do this from the example:

$myarray["foo"]["bar"]["red"]["apple"] = $some_value1;
$myarray["foo"]["bar"]["red"]["car"]   = $some_value2;
$myarray["foo"]["green"]   = $some_value3;

Is there any way to easily do this in PHP?  I could "cheat" and use eval(),
but there is probably a better way.  I have thought of using each() or
references, but nothing has come to mind so far. 

Any ideas?  Should I just use eval() ?


Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



[PHP] Multidimensional array construction

2001-12-03 Thread Darren Gamble

Here's a question for the list:

I have a two-dimensional array; essentially a list of arrays.  Each element
(an array) can have any number of elements.  As a small example:

(
  ( "foo" , "bar" , "red" , "apple" ),
  ( "foo" , "bar" , "red" , "car"),
  ( "foo" , "green" )
)

I would like to traverse this array and place all of the data into another
multidimensional array.  The following statements illustrate how I'd like to
do this from the example:

$myarray["foo"]["bar"]["red"]["apple"] = $some_value1;
$myarray["foo"]["bar"]["red"]["car"]   = $some_value2;
$myarray["foo"]["green"]   = $some_value3;

Is there any way to easily do this in PHP?  I could "cheat" and use eval(),
but there is probably a better way.  I have thought of using each() or
references, but nothing has come to mind so far. 

Any ideas?  Should I just use eval() ?


Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Multidimensional Array...

2001-10-18 Thread Roy van Pelt

Hello there...

The problem is that I can only add one value into the array...
Anyone knows what I'm doing wrong here(First project by the way!!)
=
 '', 'pname' => '', 'pqty' => ''));
  $nrItems = 0;
}

// Get variables from products.php
$productID=trim(${"pid"});
$productName=trim(${"productName"});

// Add product to offer
if ($productID!="")
{
$nrItems = $nrItems + 1;
for ($i=0; $i<$nrItems; $i=$i+1)
{
  if ($offer[$i]['pid']=="")
  {
   $productQTY = 1;
   $offer[$i]['pid'] = $productID;
   $offer[$i]['pname'] = $productName;
   $offer[$i]['pqty'] = $productQTY;
  }
}
}

//if there are no items in the offer, print a message
if ($offer[0]['pid']=="")
{
  echo "No items in the offer"."\n";
  var_dump($offer)."\n";
  echo "back";
}
//else print the contents of the offer
  else
{
for ($i=0; $i<$nrItems; $i=$i+1)
{
  echo "The offer:"."\n";

  var_dump($offer)."\n";

  echo "The offer contains items: ";
  echo $nrItems."\n";
  echo $offer[$i]['pid']."\n";
  echo $offer[$i]['pname']."\n";
  echo $offer[$i]['pqty']."\n";
  echo "\n";
  echo "back";
  echo "\n";
}
}
==

THNX in advance



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] multidimensional array from html forms

2001-10-05 Thread Larry Linthicum

Hi
I just a PHP "hobbiest" trying to build a points calculating system for
another hobby, please bear with me.

I need to build a multidimensional array from a html form
the array  would look like:

$needed_data = array (
array (id = $member_id,
points = $position ),
array ( id = $member_id,
points =$position),
array (id=$member_id,
points = $position);

$member_id  will be used to dynamically build the html form,  $position will
be an integer entered into a text field in that form
similar to this

Fred($member_id=?)   .. [ enter position=? ]
John)$member_id=?) ..[enter position=?]
etc
etc
[SUBMIT]

IF ( I can get the data into an array like above) {
I can make the rest of the script work }

but that is a big "if"  ... how can I stucture the form
and get that multidimen array from the single name/value pairs passed from
an html form?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]