Page 1 of 1

2D Array problem.

Posted: Wed Oct 10, 2007 3:15 am
by dwnthk
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi guys,

I got something like this:

Code: Select all

...
$q1 = "select ... ";
$r1 = $conn->dbExecute($q1);

   $cnt = 0;
   while ($rs1=mssql_fetch_row($r1))   {
        $arr2 = array($cnt => array($rs1[0],$rs1[1],$rs1[2],$rs1[3],$rs1[4],$rs1[5],$rs1[6],$rs1[7],$rs1[8],$rs1[9], ));
        $cnt++;
      }
      
   $cnt1 = 0;   
   while (count($arr2) > $cnt1) {     // foreach {... }  or what ever
      ...
   }


All I got in the $arr2 is the last record of the $q1. Is there something I misunderstood the use of array in the php? What I want is to get the every record in the array and loop thr' the array...

Why there is only one records in the array?

Thanks.


Dave


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: 2D Array problem.

Posted: Sun Oct 14, 2007 2:33 pm
by califdon
dwnthk wrote:

Code: Select all

...
   while ($rs1=mssql_fetch_row($r1))   {
        $arr2 = array($cnt => array($rs1[0],$rs1[1],$rs1[2],$rs1[3],$rs1[4],$rs1[5],$rs1[6],$rs1[7],$rs1[8],$rs1[9], ));
        $cnt++;
      }
All I got in the $arr2 is the last record of the $q1. Is there something I misunderstood the use of array in the php? What I want is to get the every record in the array and loop thr' the array...

Why there is only one records in the array?
Hi Dave,
Do you see that, in your while loop, every time you are completely redefining $arr2? Try something like $arr2[] = ....

Posted: Sun Oct 14, 2007 2:39 pm
by Zoxive
Why go threw all this hassle, when there already is a built in function that does this.

mssql_fetch_array

Posted: Mon Oct 15, 2007 8:10 pm
by dwnthk
Got it. :D
Thanks all.

Dave