Solved

2 dimensional arrays

Posted on 2002-06-20
8
266 Views
Last Modified: 2006-11-17
hey,

i filled a 2 - dimensional array within a loop. now i'm trying to get back my values with an index. but i just have the last value i wrote to the array. looks like every time i write something new to the array the rest is deleted ?!?

0
Comment
Question by:Zaim
  • 4
  • 2
  • 2
8 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7096065
$iN = 8; // How many locations;
$aC[0][0] = 0;
$aA[0][0] = 0;
$aP[0][0] = 0;

for ($iI = 0; $iI < $iN; $iI++)
     {
     for ($iJ = 0; $iJ < $iN; $iJ++)
          {
          $aA[$iI][$iJ] = 0;
          $aC[$iI][$iJ] = 9999;
          $aP[$iI][$iJ] = 0;
          }
     }


This is a snippet of my multi-dim array for working out the shortest route between 2 points.

What does your code look like?
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7096328
I can then access them ...

for ($iK = 0; $iK < $iN; $iK++)
     {
     for ($iI = 0; $iI < $iN; $iI++)
          {
          for ($iJ = 0; $iJ < $iN; $iJ++)
               {
               if (($aA[$iI][$iK] + $aA[$iK][$iJ]) < $aA[$iI][$iJ])
                    {
                    $aA[$iI][$iJ] = $aA[$iI][$iK] + $aA[$iK][$iJ];
                    $aP[$iI][$iJ] = $iK;
                    }
               }
          }
     }
0
 
LVL 4

Expert Comment

by:lokeshv
ID: 7097813
can u post ur code here ?


Thanks,
Lk
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:Zaim
ID: 7097868
i'm getting my data from an oracle - database. i tried the upper solution to get data through a loop, but still the same prob: i can only get the last entry

here's my code:


     if ($flag)
     {
          //if (session_is_registered("datenarray")) session_unregister("datenarray");
          $flag=0;
          //settype($datenarray,"array");
         
          for($t=0;$t<$maxid;$t++)
          {
               
          ora_fetch($cursor);
     
          $id=ora_getcolumn($cursor,0);
               err_detect($cursor);    
          $date=ora_getcolumn($cursor,1);
               err_detect($cursor);
          $comment=ora_getcolumn($cursor,2);
               err_detect($cursor);
          $erledigt=ora_getcolumn($cursor,6);
               err_detect($cursor);
          $prio=ora_getcolumn($cursor,7);
               err_detect($cursor);
         
          $datenarray[t][0] = $id;
          $datenarray[t][1] = $date;
          $datenarray[t][2] = $erledigt;
          $datenarray[t][3] = $prio;
          $datenarray[t][4] = $comment;
         
         
          //echo $datenarray[t][0].$datenarray[t][1].$datenarray[t][2].$datenarray[t][3].$datenarray[t][4];
                                                  // ---> date i just put into the array is there
          echo "<br>";
          echo count($datenarray);          // ---> always "1"
          echo "<br>";
          //echo $id;                              //working well, id is descending, like i wanted in my query
          }
               
     }
     
     
     for($i;$i < $maxid;$i++)
          {          
         

       echo "<tr>";
     /*
       for($ij=0;$ij < 5;$ij++)
            {
          echo "<td align = 'center' valign = 'center'>".$datenarray[$i][$ij]."</td>";
          }
     */
       
      echo "<td align = 'center' valign = 'center'> <input type='submit' name = id style = 'WIDTH: 80' value=$id>".$datenarray[$i][0]."</td>";
      echo "<td align = 'center' valign = 'center'>".$datenarray[$i][1]."</td>";
      echo "<td align = 'center' valign = 'center'>".$datenarray[$i][2]."</td>";
       echo "<td align = 'center' valign = 'center'>".$datenarray[$i][3]."</td>";    
       echo "<td align = 'center' valign = 'center'>".$datenarray[$i][4]."</td>";      
     
       echo "</tr>";
     
     }
     
     echo "</table>";
     
     
?>
0
 
LVL 4

Accepted Solution

by:
lokeshv earned 50 total points
ID: 7097875
$datenarray[t][0] = $id;
$datenarray[t][1] = $date;
$datenarray[t][2] = $erledigt;
$datenarray[t][3] = $prio;
$datenarray[t][4] = $comment


i think this should be '$t' instead of just 't'

Hope this solves ur problem:o)

LK
0
 

Author Comment

by:Zaim
ID: 7097924
i'm getting my data from an oracle - database. i tried the upper solution to get data through a loop, but still the same prob: i can only get the last entry

here's my code:


     if ($flag)
     {
          //if (session_is_registered("datenarray")) session_unregister("datenarray");
          $flag=0;
          //settype($datenarray,"array");
         
          for($t=0;$t<$maxid;$t++)
          {
               
          ora_fetch($cursor);
     
          $id=ora_getcolumn($cursor,0);
               err_detect($cursor);    
          $date=ora_getcolumn($cursor,1);
               err_detect($cursor);
          $comment=ora_getcolumn($cursor,2);
               err_detect($cursor);
          $erledigt=ora_getcolumn($cursor,6);
               err_detect($cursor);
          $prio=ora_getcolumn($cursor,7);
               err_detect($cursor);
         
          $datenarray[t][0] = $id;
          $datenarray[t][1] = $date;
          $datenarray[t][2] = $erledigt;
          $datenarray[t][3] = $prio;
          $datenarray[t][4] = $comment;
         
         
          //echo $datenarray[t][0].$datenarray[t][1].$datenarray[t][2].$datenarray[t][3].$datenarray[t][4];
                                                  // ---> date i just put into the array is there
          echo "<br>";
          echo count($datenarray);          // ---> always "1"
          echo "<br>";
          //echo $id;                              //working well, id is descending, like i wanted in my query
          }
               
     }
     
     
     for($i;$i < $maxid;$i++)
          {          
         

       echo "<tr>";
     /*
       for($ij=0;$ij < 5;$ij++)
            {
          echo "<td align = 'center' valign = 'center'>".$datenarray[$i][$ij]."</td>";
          }
     */
       
      echo "<td align = 'center' valign = 'center'> <input type='submit' name = id style = 'WIDTH: 80' value=$id>".$datenarray[$i][0]."</td>";
      echo "<td align = 'center' valign = 'center'>".$datenarray[$i][1]."</td>";
      echo "<td align = 'center' valign = 'center'>".$datenarray[$i][2]."</td>";
       echo "<td align = 'center' valign = 'center'>".$datenarray[$i][3]."</td>";    
       echo "<td align = 'center' valign = 'center'>".$datenarray[$i][4]."</td>";      
     
       echo "</tr>";
     
     }
     
     echo "</table>";
     
     
?>
0
 

Author Comment

by:Zaim
ID: 7098134
i'm getting my data from an oracle - database. i tried the upper solution to get data through a loop, but still the same prob: i can only get the last entry

here's my code:


     if ($flag)
     {
          //if (session_is_registered("datenarray")) session_unregister("datenarray");
          $flag=0;
          //settype($datenarray,"array");
         
          for($t=0;$t<$maxid;$t++)
          {
               
          ora_fetch($cursor);
     
          $id=ora_getcolumn($cursor,0);
               err_detect($cursor);    
          $date=ora_getcolumn($cursor,1);
               err_detect($cursor);
          $comment=ora_getcolumn($cursor,2);
               err_detect($cursor);
          $erledigt=ora_getcolumn($cursor,6);
               err_detect($cursor);
          $prio=ora_getcolumn($cursor,7);
               err_detect($cursor);
         
          $datenarray[t][0] = $id;
          $datenarray[t][1] = $date;
          $datenarray[t][2] = $erledigt;
          $datenarray[t][3] = $prio;
          $datenarray[t][4] = $comment;
         
         
          //echo $datenarray[t][0].$datenarray[t][1].$datenarray[t][2].$datenarray[t][3].$datenarray[t][4];
                                                  // ---> date i just put into the array is there
          echo "<br>";
          echo count($datenarray);          // ---> always "1"
          echo "<br>";
          //echo $id;                              //working well, id is descending, like i wanted in my query
          }
               
     }
     
     
     for($i;$i < $maxid;$i++)
          {          
         

       echo "<tr>";
     /*
       for($ij=0;$ij < 5;$ij++)
            {
          echo "<td align = 'center' valign = 'center'>".$datenarray[$i][$ij]."</td>";
          }
     */
       
      echo "<td align = 'center' valign = 'center'> <input type='submit' name = id style = 'WIDTH: 80' value=$id>".$datenarray[$i][0]."</td>";
      echo "<td align = 'center' valign = 'center'>".$datenarray[$i][1]."</td>";
      echo "<td align = 'center' valign = 'center'>".$datenarray[$i][2]."</td>";
       echo "<td align = 'center' valign = 'center'>".$datenarray[$i][3]."</td>";    
       echo "<td align = 'center' valign = 'center'>".$datenarray[$i][4]."</td>";      
     
       echo "</tr>";
     
     }
     
     echo "</table>";
     
     
?>
0
 

Author Comment

by:Zaim
ID: 7098155
thanks for help.

that's the kind of mistakes nobody thinks to make but everyone does. there it needs 2 other eyes to look at ;)

----> it's workin'
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now