Page 1 of 1

split a huge array into fixed number of values arrays

Posted: Fri Jul 21, 2006 6:36 pm
by Da P3s7
I have this function

Code: Select all

function mysql_fetch_all($result) {
   $i = 0;
   for ($i=0; $i<mysql_num_rows($result); $i++) {
       $return[$i] = mysql_fetch_array($result);
   }
   return $return;
}
When i do a print_r on the mysql_fetch_all($select) where $select is the result from a select query i get

Code: Select all

Array ( [0] => Array ( [0] => 1 [Index] => 1 [1] => aa [Name] => aa [2] => bb [Description] => bb [3] => cc [Path] => cc [4] => 0 [Executed] => 0 [5] => 0 [Sold] => 0 [6] => 0 [Price] => 0 ) [1] => Array ( [0] => 2 [Index] => 2 [1] => ba [Name] => ba [2] => ab [Description] => ab [3] => c [Path] => c [4] => 1 [Executed] => 1 [5] => 2 [Sold] => 2 [6] => 3 [Price] => 3 ) [2] => Array ( [0] => 3 [Index] => 3 [1] => a [Name] => a [2] => b [Description] => b [3] => c [Path] => c [4] => 0 [Executed] => 0 [5] => 0 [Sold] => 0 [6] => 0 [Price] => 0 ) [3] => Array ( [0] => 4 [Index] => 4 [1] => ab [Name] => ab [2] => cb [Description] => cb [3] => db [Path] => db [4] => 12 [Executed] => 12 [5] => 32 [Sold] => 32 [6] => 42 [Price] => 42 ) [4] => Array ( [0] => 5 [Index] => 5 [1] => 200 caractere si speci8ale #@$#ET$^%%$^^* [Name] => ab [2] => ab [Description] => ba [3] => [Path] => [4] => 123 [Executed] => 123 [5] => 0 [Sold] => 0 [6] => 12.2 [Price] => 12.2 ) )
Is there a way that i can simply split up this array into smaller arrays that i can use, no matter the size of the DB ?....
I mean something like $result1, $result2 or something and auto-incrementing.... I would then use that to display just That row.
Would implode() do the job?

Posted: Fri Jul 21, 2006 6:39 pm
by Benjamin
Something like this might work for you..

Code: Select all

foreach ($array as $record) {
  foreach ($record as $values) {

  }
}

Posted: Fri Jul 21, 2006 6:56 pm
by Da P3s7
umm i think that i dont need an array for each value...
and second i THINK that i need the arrays extracted to be static...(i think)
I say i think becouse i still havent written the code that will actually use this....
It's like a big puzzle in my mind...i seem to have the pieces but can't seem to make them fit together. :?

Re: split a huge array into fixed number of values arrays

Posted: Fri Jul 21, 2006 7:04 pm
by Benjamin
Da P3s7 wrote: Is there a way that i can simply split up this array into smaller arrays that i can use, no matter the size of the DB ?....
Did I not answer your question?

Posted: Fri Jul 21, 2006 7:07 pm
by Da P3s7
Sorry. It's my mistake i didnt make myself clear.... :oops: :oops:

Posted: Fri Jul 21, 2006 7:13 pm
by Benjamin
You can access the rows without the foreach by doing this..

Code: Select all

print_r($result[$recordNumber]);


// and specific fields with..
echo $result[$recordNumber]['fieldName'];
echo $result[$recordNumber]['fieldName2'];