Re: [PHP] Creating multidimensional array dynamically

2001-12-06 Thread Mike Eheler

Oops.. my bad
$quarterbacks[$data['NAME']][$key] = $value;

Mike

Mike Eheler wrote:

> $result = mysql_query("select NAME,ATTEMPTS,COMPLETIONS,YARDS,TD,INT 
> from players where pos = 'QB'");
> // or whatever it takes to get just qb's
> while ($data = mysql_fetch_array($result)) {
>foreach ($data as $key => $value) {
>// I've noticed that $data stores numeric and text keys, this 
> filters the numeric ones
>if (!is_numeric($key)) {
>$quarterbacks[$name][$key] = $value;
>}
>}
> }
>
> That's how I'd do it.. a little extra work, but it keeps only the data 
> you want on hand.
>
> It's also a good idea to store the name so you can reference later if 
> you want to spew forth all the qbs..
>
> Mike
>
> J. Roberts wrote:
>
>> I can't seem to figure out how to create a multidimensional array from
>> a database query.  Here is an example of what I was looking for, using
>> NFL quarterbacks as a statistical foundation...
>> A record contains the following fields:
>>
>> NAME, ATTEMPTS, COMPLETIONS, YARDS, TD, INT
>>
>> Now I would like to be able to create an array with NAME as a key 
>> containing
>> the array(ATTEMPTS, COMPLETIONS, YARDS, TD, INT).
>>
>> That way I would be able to do the following:
>>
>> echo $quarterbacks["GARCIA"]["YARDS"];
>>
>> and get the output of 3,100 or whatever the case may be.
>>
>> Thanks,
>> -Jamison.
>>
>>
>>
>
>
>



-- 
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] Creating multidimensional array dynamically

2001-12-06 Thread Mike Eheler

$result = mysql_query("select NAME,ATTEMPTS,COMPLETIONS,YARDS,TD,INT 
from players where pos = 'QB'");
// or whatever it takes to get just qb's
while ($data = mysql_fetch_array($result)) {
foreach ($data as $key => $value) {
// I've noticed that $data stores numeric and text keys, this 
filters the numeric ones
if (!is_numeric($key)) {
$quarterbacks[$name][$key] = $value;
}
}
}

That's how I'd do it.. a little extra work, but it keeps only the data 
you want on hand.

It's also a good idea to store the name so you can reference later if 
you want to spew forth all the qbs..

Mike

J. Roberts wrote:

>I can't seem to figure out how to create a multidimensional array from
>a database query.  Here is an example of what I was looking for, using
>NFL quarterbacks as a statistical foundation...
>A record contains the following fields:
>
>NAME, ATTEMPTS, COMPLETIONS, YARDS, TD, INT
>
>Now I would like to be able to create an array with NAME as a key containing
>the array(ATTEMPTS, COMPLETIONS, YARDS, TD, INT).
>
>That way I would be able to do the following:
>
>echo $quarterbacks["GARCIA"]["YARDS"];
>
>and get the output of 3,100 or whatever the case may be.
>
>Thanks,
>-Jamison.
>
>
>



-- 
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] Creating multidimensional array dynamically

2001-12-06 Thread jimtronic


you could also do this ...

$data = mysql_fetch_assoc($res); //this is a nice function because it 
returns an associative array. so
// if you change your SQL db, you 
wouldn't need to change your php code
// as much.

$quarterbacks[$name]= $data;


jim




>Something like this?
>
>while( list( $name, $attempts, $completions, $yards, $td, $int ) =
>mysql_fetch_row($res) )
>{
>   $quarterbacks[$name] = array( "ATTEMPTS" => $attempts,
>   "COMPLETIONS" =>
>$completions,
>   "YARDS" => $yards,
>   "TD" => $td,
>   "INT" => $int );
>}
>
>echo $quarterbacks["GARCIA"]["YARDS"];
>
>Jason Lotito
>[EMAIL PROTECTED]
>www.NewbieNetwork.net
>
>>  -Original Message-
>>  From: J. Roberts [mailto:[EMAIL PROTECTED]]
>>  Sent: Thursday, December 06, 2001 4:08 PM
>>  To: [EMAIL PROTECTED]
>>  Subject: [PHP] Creating multidimensional array dynamically
>>
>>
>>  I can't seem to figure out how to create a multidimensional
>>  array from a database query.  Here is an example of what I
>>  was looking for, using NFL quarterbacks as a statistical
>>  foundation... A record contains the following fields:
>>
>>  NAME, ATTEMPTS, COMPLETIONS, YARDS, TD, INT
>>
>>  Now I would like to be able to create an array with NAME as a
>>  key containing the array(ATTEMPTS, COMPLETIONS, YARDS, TD, INT).
>>
>>  That way I would be able to do the following:
>>
>>  echo $quarterbacks["GARCIA"]["YARDS"];
>>
>>  and get the output of 3,100 or whatever the case may be.
>>
>>  Thanks,
>>  -Jamison.
>>
>>
>>
>>  --
>>  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 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] Creating multidimensional array dynamically

2001-12-06 Thread Dennis Moore

Not sure what you are trying to do, but try using

mysql_fetch_row ()

you can use SQL to limit your results.

/dkm


- Original Message -
From: "J. Roberts" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, December 06, 2001 4:08 PM
Subject: [PHP] Creating multidimensional array dynamically


> I can't seem to figure out how to create a multidimensional array from
> a database query.  Here is an example of what I was looking for, using
> NFL quarterbacks as a statistical foundation...
> A record contains the following fields:
>
> NAME, ATTEMPTS, COMPLETIONS, YARDS, TD, INT
>
> Now I would like to be able to create an array with NAME as a key
containing
> the array(ATTEMPTS, COMPLETIONS, YARDS, TD, INT).
>
> That way I would be able to do the following:
>
> echo $quarterbacks["GARCIA"]["YARDS"];
>
> and get the output of 3,100 or whatever the case may be.
>
> Thanks,
> -Jamison.
>
>
>
> --
> 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 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] Creating multidimensional array dynamically

2001-12-06 Thread Jason Lotito

Something like this?

while( list( $name, $attempts, $completions, $yards, $td, $int ) =
mysql_fetch_row($res) )
{
$quarterbacks[$name] = array( "ATTEMPTS" => $attempts,
"COMPLETIONS" =>
$completions,
"YARDS" => $yards,
"TD" => $td,
"INT" => $int );
}

echo $quarterbacks["GARCIA"]["YARDS"];

Jason Lotito
[EMAIL PROTECTED]
www.NewbieNetwork.net

> -Original Message-
> From: J. Roberts [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, December 06, 2001 4:08 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Creating multidimensional array dynamically
> 
> 
> I can't seem to figure out how to create a multidimensional 
> array from a database query.  Here is an example of what I 
> was looking for, using NFL quarterbacks as a statistical 
> foundation... A record contains the following fields:
> 
> NAME, ATTEMPTS, COMPLETIONS, YARDS, TD, INT
> 
> Now I would like to be able to create an array with NAME as a 
> key containing the array(ATTEMPTS, COMPLETIONS, YARDS, TD, INT).
> 
> That way I would be able to do the following:
> 
> echo $quarterbacks["GARCIA"]["YARDS"];
> 
> and get the output of 3,100 or whatever the case may be.
> 
> Thanks,
> -Jamison.
> 
> 
> 
> -- 
> 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 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]