Re: [PHP] Nested Arrays

2002-12-27 Thread Marek Kilimajer
Simple:

while($rows[]=mysql_fetch_array($res)) {}

($res is a mysql result resource)

Beauford.2002 wrote:


Thanks for the info, but maybe I didn't give enough info.

I have a mysql database with up to 10 rows and 5 fields in each row.. I have
been reading up on some of the array functions, but haven't been able to get
anything to work.

TIA

- Original Message -
From: Weston Houghton [EMAIL PROTECTED]
To: Beauford.2002 [EMAIL PROTECTED]
Cc: PHP General [EMAIL PROTECTED]
Sent: Thursday, December 26, 2002 6:19 PM
Subject: Re: [PHP] Nested Arrays


 

Sure... for the longwinded approach, just do this:

$row1 = array(col1, col2, col3, ...);
$row2 = array(col1, col2, col3, ...);
$row3 = array(col1, col2, col3, ...);
$row4 = array(col1, col2, col3, ...);
$row5 = array(col1, col2, col3, ...);

$main_array = array($row1, $row2, $row3, $row4, $row5);

Obviously these could include key-value pairs in the arrays as well.
Then to prove it to yourself:

print_r($main_array);

Cheers,
Wes


On Thursday, December 26, 2002, at 06:14  PM, Beauford.2002 wrote:

   

Hi,

Is there anyway to do a nested array, I have looked at the various
array
functions and can't figure this out (if possible).

I want to be able to put each field of  a row into an array, and then
put
that entire row and into another array.

so when I display it, I would have:

row1 - col1  col2  col3 col4 col5
row2 - col1  col2  col3 col4 col5
row3 - col1  col2  col3 col4 col5
row4 - col1  col2  col3 col4 col5
row5 - col1  col2  col3 col4 col5

etc. (depending on how many rows there are).

TIA



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


 

   




 



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




Re: [PHP] Nested Arrays

2002-12-27 Thread Marek Kilimajer
Sorry, now I reminded myself this would cause a false element at the end 
of $rows, use this:
while($tmp=mysql_fetch_array($res)) {
   $rows[]=$tmp;
}

Marek Kilimajer wrote:

Simple:

while($rows[]=mysql_fetch_array($res)) {}

($res is a mysql result resource)

Beauford.2002 wrote:


Thanks for the info, but maybe I didn't give enough info.

I have a mysql database with up to 10 rows and 5 fields in each row.. 
I have
been reading up on some of the array functions, but haven't been able 
to get
anything to work.

TIA

- Original Message -
From: Weston Houghton [EMAIL PROTECTED]
To: Beauford.2002 [EMAIL PROTECTED]
Cc: PHP General [EMAIL PROTECTED]
Sent: Thursday, December 26, 2002 6:19 PM
Subject: Re: [PHP] Nested Arrays


 

Sure... for the longwinded approach, just do this:

$row1 = array(col1, col2, col3, ...);
$row2 = array(col1, col2, col3, ...);
$row3 = array(col1, col2, col3, ...);
$row4 = array(col1, col2, col3, ...);
$row5 = array(col1, col2, col3, ...);

$main_array = array($row1, $row2, $row3, $row4, $row5);

Obviously these could include key-value pairs in the arrays as well.
Then to prove it to yourself:

print_r($main_array);

Cheers,
Wes


On Thursday, December 26, 2002, at 06:14  PM, Beauford.2002 wrote:

  

Hi,

Is there anyway to do a nested array, I have looked at the various
array
functions and can't figure this out (if possible).

I want to be able to put each field of  a row into an array, and then
put
that entire row and into another array.

so when I display it, I would have:

row1 - col1  col2  col3 col4 col5
row2 - col1  col2  col3 col4 col5
row3 - col1  col2  col3 col4 col5
row4 - col1  col2  col3 col4 col5
row5 - col1  col2  col3 col4 col5

etc. (depending on how many rows there are).

TIA



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




  




 






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




Re: [PHP] Nested Arrays

2002-12-27 Thread Beauford.2002
Great. now can you explain why this works.  I'm confused at how PHP knows
this is a multidimensional array. I was trying something like $tmp[][]=???.

TIA

- Original Message -
From: Marek Kilimajer [EMAIL PROTECTED]
Cc: Beauford.2002 [EMAIL PROTECTED]; PHP General
[EMAIL PROTECTED]
Sent: Friday, December 27, 2002 8:45 AM
Subject: Re: [PHP] Nested Arrays


 Sorry, now I reminded myself this would cause a false element at the end
 of $rows, use this:
 while($tmp=mysql_fetch_array($res)) {
 $rows[]=$tmp;
 }

 Marek Kilimajer wrote:

  Simple:
 
  while($rows[]=mysql_fetch_array($res)) {}
 
  ($res is a mysql result resource)
 
  Beauford.2002 wrote:
 
  Thanks for the info, but maybe I didn't give enough info.
 
  I have a mysql database with up to 10 rows and 5 fields in each row..
  I have
  been reading up on some of the array functions, but haven't been able
  to get
  anything to work.
 
  TIA
 
  - Original Message -
  From: Weston Houghton [EMAIL PROTECTED]
  To: Beauford.2002 [EMAIL PROTECTED]
  Cc: PHP General [EMAIL PROTECTED]
  Sent: Thursday, December 26, 2002 6:19 PM
  Subject: Re: [PHP] Nested Arrays
 
 
 
 
  Sure... for the longwinded approach, just do this:
 
  $row1 = array(col1, col2, col3, ...);
  $row2 = array(col1, col2, col3, ...);
  $row3 = array(col1, col2, col3, ...);
  $row4 = array(col1, col2, col3, ...);
  $row5 = array(col1, col2, col3, ...);
 
  $main_array = array($row1, $row2, $row3, $row4, $row5);
 
  Obviously these could include key-value pairs in the arrays as well.
  Then to prove it to yourself:
 
  print_r($main_array);
 
  Cheers,
  Wes
 
 
  On Thursday, December 26, 2002, at 06:14  PM, Beauford.2002 wrote:
 
 
 
  Hi,
 
  Is there anyway to do a nested array, I have looked at the various
  array
  functions and can't figure this out (if possible).
 
  I want to be able to put each field of  a row into an array, and then
  put
  that entire row and into another array.
 
  so when I display it, I would have:
 
  row1 - col1  col2  col3 col4 col5
  row2 - col1  col2  col3 col4 col5
  row3 - col1  col2  col3 col4 col5
  row4 - col1  col2  col3 col4 col5
  row5 - col1  col2  col3 col4 col5
 
  etc. (depending on how many rows there are).
 
  TIA
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 
 
 
 
 
 
 
 
 


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





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




Re: [PHP] Nested Arrays

2002-12-27 Thread Marek Kilimajer
while($tmp=mysql_fetch_array($res)) { // now $tmp is now an array (as the function name suggests)
   $rows[]=$tmp; // by assigning to $rows[], we make $rows an array, adding array $tmp as the last element
}

and this makes it multidimensional



Beauford.2002 wrote:


Great. now can you explain why this works.  I'm confused at how PHP knows
this is a multidimensional array. I was trying something like $tmp[][]=???.

TIA

- Original Message -
From: Marek Kilimajer [EMAIL PROTECTED]
Cc: Beauford.2002 [EMAIL PROTECTED]; PHP General
[EMAIL PROTECTED]
Sent: Friday, December 27, 2002 8:45 AM
Subject: Re: [PHP] Nested Arrays


 

Sorry, now I reminded myself this would cause a false element at the end
of $rows, use this:
while($tmp=mysql_fetch_array($res)) {
   $rows[]=$tmp;
}

Marek Kilimajer wrote:

   

Simple:

while($rows[]=mysql_fetch_array($res)) {}

($res is a mysql result resource)
 



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




Re: [PHP] Nested Arrays

2002-12-27 Thread Michael J. Pawlowsky


Stop thinking of it as a multidimesional array.
It is simply an two dimensional array of two dimensional arrays.







*** REPLY SEPARATOR  ***

On 27/12/2002 at 11:29 AM Beauford.2002 wrote:

Great. now can you explain why this works.  I'm confused at how PHP knows
this is a multidimensional array. I was trying something like $tmp[][]=???.

TIA

- Original Message -
From: Marek Kilimajer [EMAIL PROTECTED]
Cc: Beauford.2002 [EMAIL PROTECTED]; PHP General
[EMAIL PROTECTED]
Sent: Friday, December 27, 2002 8:45 AM
Subject: Re: [PHP] Nested Arrays


 Sorry, now I reminded myself this would cause a false element at the end
 of $rows, use this:
 while($tmp=mysql_fetch_array($res)) {
 $rows[]=$tmp;
 }

 Marek Kilimajer wrote:

  Simple:
 
  while($rows[]=mysql_fetch_array($res)) {}
 
  ($res is a mysql result resource)
 
  Beauford.2002 wrote:
 
  Thanks for the info, but maybe I didn't give enough info.
 
  I have a mysql database with up to 10 rows and 5 fields in each row..
  I have
  been reading up on some of the array functions, but haven't been able
  to get
  anything to work.
 
  TIA
 
  - Original Message -
  From: Weston Houghton [EMAIL PROTECTED]
  To: Beauford.2002 [EMAIL PROTECTED]
  Cc: PHP General [EMAIL PROTECTED]
  Sent: Thursday, December 26, 2002 6:19 PM
  Subject: Re: [PHP] Nested Arrays
 
 
 
 
  Sure... for the longwinded approach, just do this:
 
  $row1 = array(col1, col2, col3, ...);
  $row2 = array(col1, col2, col3, ...);
  $row3 = array(col1, col2, col3, ...);
  $row4 = array(col1, col2, col3, ...);
  $row5 = array(col1, col2, col3, ...);
 
  $main_array = array($row1, $row2, $row3, $row4, $row5);
 
  Obviously these could include key-value pairs in the arrays as well.
  Then to prove it to yourself:
 
  print_r($main_array);
 
  Cheers,
  Wes
 
 
  On Thursday, December 26, 2002, at 06:14  PM, Beauford.2002 wrote:
 
 
 
  Hi,
 
  Is there anyway to do a nested array, I have looked at the various
  array
  functions and can't figure this out (if possible).
 
  I want to be able to put each field of  a row into an array, and
then
  put
  that entire row and into another array.
 
  so when I display it, I would have:
 
  row1 - col1  col2  col3 col4 col5
  row2 - col1  col2  col3 col4 col5
  row3 - col1  col2  col3 col4 col5
  row4 - col1  col2  col3 col4 col5
  row5 - col1  col2  col3 col4 col5
 
  etc. (depending on how many rows there are).
 
  TIA
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 
 
 
 
 
 
 
 
 


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





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





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




Re: [PHP] Nested Arrays

2002-12-27 Thread Beauford.2002
OK, little bit of a brain cramp here. I wasn't clueing in that
$tmp=mysql_fetch_array($res) was an array and was trying to do something
again that was already there.

Thanks for the help.

Beauford

- Original Message -
From: Marek Kilimajer [EMAIL PROTECTED]
To: Beauford.2002 [EMAIL PROTECTED]
Cc: PHP General [EMAIL PROTECTED]
Sent: Friday, December 27, 2002 11:41 AM
Subject: Re: [PHP] Nested Arrays


 while($tmp=mysql_fetch_array($res)) { // now $tmp is now an array (as the
function name suggests)
 $rows[]=$tmp; // by assigning to $rows[], we make $rows an array,
adding array $tmp as the last element
 }

 and this makes it multidimensional



 Beauford.2002 wrote:

 Great. now can you explain why this works.  I'm confused at how PHP knows
 this is a multidimensional array. I was trying something like
$tmp[][]=???.
 
 TIA
 
 - Original Message -
 From: Marek Kilimajer [EMAIL PROTECTED]
 Cc: Beauford.2002 [EMAIL PROTECTED]; PHP General
 [EMAIL PROTECTED]
 Sent: Friday, December 27, 2002 8:45 AM
 Subject: Re: [PHP] Nested Arrays
 
 
 
 
 Sorry, now I reminded myself this would cause a false element at the end
 of $rows, use this:
 while($tmp=mysql_fetch_array($res)) {
 $rows[]=$tmp;
 }
 
 Marek Kilimajer wrote:
 
 
 
 Simple:
 
 while($rows[]=mysql_fetch_array($res)) {}
 
 ($res is a mysql result resource)
 
 


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





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




[PHP] Nested Arrays

2002-12-26 Thread Beauford.2002
Hi,

Is there anyway to do a nested array, I have looked at the various array
functions and can't figure this out (if possible).

I want to be able to put each field of  a row into an array, and then put
that entire row and into another array.

so when I display it, I would have:

row1 - col1  col2  col3 col4 col5
row2 - col1  col2  col3 col4 col5
row3 - col1  col2  col3 col4 col5
row4 - col1  col2  col3 col4 col5
row5 - col1  col2  col3 col4 col5

etc. (depending on how many rows there are).

TIA



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




Re: [PHP] Nested Arrays

2002-12-26 Thread Weston Houghton

Sure... for the longwinded approach, just do this:

$row1 = array(col1, col2, col3, ...);
$row2 = array(col1, col2, col3, ...);
$row3 = array(col1, col2, col3, ...);
$row4 = array(col1, col2, col3, ...);
$row5 = array(col1, col2, col3, ...);

$main_array = array($row1, $row2, $row3, $row4, $row5);

Obviously these could include key-value pairs in the arrays as well. 
Then to prove it to yourself:

print_r($main_array);

Cheers,
Wes


On Thursday, December 26, 2002, at 06:14  PM, Beauford.2002 wrote:

Hi,

Is there anyway to do a nested array, I have looked at the various 
array
functions and can't figure this out (if possible).

I want to be able to put each field of  a row into an array, and then 
put
that entire row and into another array.

so when I display it, I would have:

row1 - col1  col2  col3 col4 col5
row2 - col1  col2  col3 col4 col5
row3 - col1  col2  col3 col4 col5
row4 - col1  col2  col3 col4 col5
row5 - col1  col2  col3 col4 col5

etc. (depending on how many rows there are).

TIA



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




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




Re: [PHP] Nested Arrays

2002-12-26 Thread Weston Houghton

Sure... for the longwinded approach, just do this:

$row1 = array(col1, col2, col3, ...);
$row2 = array(col1, col2, col3, ...);
$row3 = array(col1, col2, col3, ...);
$row4 = array(col1, col2, col3, ...);
$row5 = array(col1, col2, col3, ...);

$main_array = array($row1, $row2, $row3, $row4, $row5);

Obviously these could include key-value pairs in the arrays as well. 
Then to prove it to yourself:

print_r($main_array);

Cheers,
Wes



On Thursday, December 26, 2002, at 06:14  PM, Beauford.2002 wrote:

Hi,

Is there anyway to do a nested array, I have looked at the various 
array
functions and can't figure this out (if possible).

I want to be able to put each field of  a row into an array, and then 
put
that entire row and into another array.

so when I display it, I would have:

row1 - col1  col2  col3 col4 col5
row2 - col1  col2  col3 col4 col5
row3 - col1  col2  col3 col4 col5
row4 - col1  col2  col3 col4 col5
row5 - col1  col2  col3 col4 col5

etc. (depending on how many rows there are).

TIA



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




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




Re: [PHP] Nested Arrays

2002-12-26 Thread Wee Keat [Amorphosium]


 Is there anyway to do a nested array, I have looked at the various array
 functions and can't figure this out (if possible).
 
Try reading up on multidimensional array...

http://www.onlamp.com/pub/a/php/2001/06/07/php_foundations.html
http://www.onlamp.com/pub/a/php/2001/06/21/php_foundations.html

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

HTH.


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




Re: [PHP] Nested Arrays

2002-12-26 Thread Beauford.2002
Thanks for the info, but maybe I didn't give enough info.

I have a mysql database with up to 10 rows and 5 fields in each row.. I have
been reading up on some of the array functions, but haven't been able to get
anything to work.

TIA

- Original Message -
From: Weston Houghton [EMAIL PROTECTED]
To: Beauford.2002 [EMAIL PROTECTED]
Cc: PHP General [EMAIL PROTECTED]
Sent: Thursday, December 26, 2002 6:19 PM
Subject: Re: [PHP] Nested Arrays



 Sure... for the longwinded approach, just do this:

 $row1 = array(col1, col2, col3, ...);
 $row2 = array(col1, col2, col3, ...);
 $row3 = array(col1, col2, col3, ...);
 $row4 = array(col1, col2, col3, ...);
 $row5 = array(col1, col2, col3, ...);

 $main_array = array($row1, $row2, $row3, $row4, $row5);

 Obviously these could include key-value pairs in the arrays as well.
 Then to prove it to yourself:

 print_r($main_array);

 Cheers,
 Wes


 On Thursday, December 26, 2002, at 06:14  PM, Beauford.2002 wrote:

  Hi,
 
  Is there anyway to do a nested array, I have looked at the various
  array
  functions and can't figure this out (if possible).
 
  I want to be able to put each field of  a row into an array, and then
  put
  that entire row and into another array.
 
  so when I display it, I would have:
 
  row1 - col1  col2  col3 col4 col5
  row2 - col1  col2  col3 col4 col5
  row3 - col1  col2  col3 col4 col5
  row4 - col1  col2  col3 col4 col5
  row5 - col1  col2  col3 col4 col5
 
  etc. (depending on how many rows there are).
 
  TIA
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 





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




Re: [PHP] Nested Arrays

2002-12-26 Thread Wee Keat [Amorphosium]

- Original Message -
From: Beauford.2002 [EMAIL PROTECTED]
To: Wee Keat [Amorphosium] [EMAIL PROTECTED]
Sent: Friday, December 27, 2002 12:13 PM
Subject: Re: [PHP] Nested Arrays


 Quote: I have looked at the various array functions and can't figure this
 out .


Wow... You're welcome!


 
 
   Is there anyway to do a nested array, I have looked at the various
array
   functions and can't figure this out (if possible).
  
  Try reading up on multidimensional array...
 
  http://www.onlamp.com/pub/a/php/2001/06/07/php_foundations.html
  http://www.onlamp.com/pub/a/php/2001/06/21/php_foundations.html
 
  http://www.php.net/manual/en/function.array.php
 
  HTH.
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 






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




RE: [PHP] Nested Arrays

2002-12-26 Thread Paul Reed
I didn't see this approach in any other reply. 

A multidimensional array is just an array of single dimensional
arrays... Basically $array[row#][col#]=$data;
$array[0][0]= row0, col0; 
$array[0][1]= row0, col1;

This also works with associative arrays...

$cars[0]['make']=Ford;
$cars[0]['model']=Mustang;
$cars[1]['make']=Mazda;
$cars[1]['model']=RX7;

Although using an object/class would be better suited for the second
example

Hope this help .. 

Paul.

-Original Message-
From: Beauford.2002 [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, December 26, 2002 18:14
To: PHP General
Subject: [PHP] Nested Arrays

Hi,

Is there anyway to do a nested array, I have looked at the various array
functions and can't figure this out (if possible).

I want to be able to put each field of  a row into an array, and then
put
that entire row and into another array.

so when I display it, I would have:

row1 - col1  col2  col3 col4 col5
row2 - col1  col2  col3 col4 col5
row3 - col1  col2  col3 col4 col5
row4 - col1  col2  col3 col4 col5
row5 - col1  col2  col3 col4 col5

etc. (depending on how many rows there are).

TIA



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



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