Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
2D arrays and looping
Old 06-23-2010, 02:25 AM 2D arrays and looping
Extreme Talker

Posts: 173
Trades: 0
I think I have the logic but not using the right methods.

I believe I am importing the data correctly into my arrays, however when I try to determine the array size I am getting an incorrect count. Think I may be using functions incorrectly but not sure of the correct one.

I have data as follows:

PO value
AA 100
BB 200
CC 300


PO MILESTONES
AA ON ORDER AWARD
AA ON DRAWING RELEASE
AA ON SHIPMENT
BB ON START UP
BB ON ORDER AWARD
BB ON DRAWING RELEASE
BB ON SHIPMENT
BB ON START UP
CC ON ORDER AWARD
CC ON DRAWING RELEASE
CC ON SHIPMENT
CC ON START UP

Currently I am scanning through and loading the PO values and Milestones into 2-2D arrays and then I want to dump the data.

When I try to determine the sizeof (count) the array, am getting 7 when I am expecting 4 or maybe 3 depending on if it counts the zero position.

PHP Code:
<?php
 
// start session 
session_start();
// set up global variables 
@include 'menu.php';
@include 
'menu_project.php';
@include 
'globalcfg.php';
@include 
'db_connect.php';
//Create team list
if(!isset($_SESSION["project_id"])) die;
$sql =  'SELECT * FROM tbl_financials WHERE tbl_financials.project_id='.$_SESSION["project_id"].' ORDER BY po_number ASC';
$result mysql_query($sql$link);
 echo 
$sql.'<br />';

if (!
$result) {
  echo 
'DB Error, could not query the database MySQL Error: '.mysql_error();
  exit;
}
$x=0;
$y=0;
$z=0;
while (
$row mysql_fetch_assoc($result)) {  
 
$sql =  'SELECT * FROM tbl_milestone WHERE financials_id='.$row['financials_id'].' ORDER BY milestone ASC';
 echo 
$sql.'<br />';
 
$result1 mysql_query($sql$link);
 if (!
$result1) {
   echo 
'DB Error, could not query the database MySQL Error: '.mysql_error();
   exit;
 }
 if(!empty(
$row['po_value'])){
  
$po[$x][0]=$row['po_number'];
  
$po[$x][1]=$row['po_date'];
  
$po[$x][2]=$row['po_value'];
  
$po[$x][3]=$row['currency'];
  while (
$row1 mysql_fetch_assoc($result1)){
   
$milestone[$x][$y][$z++]=$row1['milestone'];
   
$milestone[$x][$y][$z++]=$row1['description'];
   
$milestone[$x][$y][$z++]=$row1['percentage'];
   
$milestone[$x][$y][$z++]=$row['po_value']*$row1['percentage']/100;
   
$milestone[$x][$y][$z++]=$row1['baseline'];
   
$milestone[$x][$y][$z++]=$row1['estimated'];
   
$milestone[$x][$y][$z++]=$row1['actual'];
   if(!empty(
$value[$x][$y++])) $project_value=+$value[$x][$y++];
   
$z=0;
  } 
 }
 else{
  
$po[$x][0]=$row['po_number'];
  
$po[$x][1]=$row['po_date'];
  
$po[$x][3]=$row['po_currency'];
  while (
$row1 mysql_fetch_assoc($result)){
   
$milestone[$x][$y][$z++]=$row1['milestone'];
   
$milestone[$x][$y][$z++]=$row1['description'];
   
$milestone[$x][$y][$z++]= $row1['value']/$row['po_value']*100;
   
$milestone[$x][$y][$z++]=$row1['value'];
   
$milestone[$x][$y][$z++]=$row1['baseline'];
   
$milestone[$x][$y][$z++]=$row1['estimated'];
   
$milestone[$x][$y][$z++]=$row1['actual'];
   
$po[$x][2]=+$row['po_value'];
   
$project_value+=$value[$x][$y++];
   
$z=0;
  }
  
$x++; 
 }
 
}
if (empty(
$project_value)) $project_value=0;
echo 
'<html><body>'.
  
'<table class="datagrid">'.
  
'<tr>'.
      
'<td>Total Project Value:&nbsp&nbsp&nbsp'.number_format($project_value2'.'',').'</td>'.
  
'</tr>'.
  
'<tr>'.
      
'<th><b>Purchase Order</b></th>'.
      
'<th><b>Date</b></th>'.
      
'<th><b>Value</b></th>'.
      
'<th><b>Currency</b></th>'.
      
'<th><b>Milestone</b></th>'.
      
'<th><b>Description</b></th>'.
      
'<th><b>Percentage</b></th>'.
      
'<th><b>Value</b></th>'.
      
'<th><b>Baseline</b></th>'.
      
'<th><b>Estimated</b></th>'.
      
'<th><b>Actual</b></th>'.
  
'</tr>';
$a=0;
$b=0;
$i=0;
for(
$x=0;$x<count($po[$x]);$x++){
                     echo 
count($po[$x]);
 for(
$y=0;$y<count($milestone[$x][$y]);$y++){
                      echo 
count($milestone[$x][$y]);
  
$i++;
  echo
'<tr class=d'.($i 1).'>';
   if(empty(
$y)){ //prints PO details on first row
       
echo'<td>'.$po[$x][$a++].'</td>'.        //PO number
        
'<td>'.$po[$x][$a++].'</td>'.        //PO date
        
'<td>'.number_format($po[$x][$a++], 2'.'',').'</td>'//PO value
        
'<td>'.$po[$x][$a++].'</td>';        //Currency
   
}
   else{  
//prints blank cells on duplicate row
        
echo'<td></td>'.
         
'<td></td>'.
         
'<td></td>'.
         
'<td></td>';
   }
   echo
'<td>'.$milestone[$x][$y][$b++].'</td>'.        //Index
       
'<td>'.$milestone[$x][$y][$b++].'</td>'.        //Description
    
'<td>'.number_format($milestone[$x][$y][$b++], 2'.'',').'</td>'//percentage
       
'<td>'.number_format($milestone[$x][$y][$b++], 2'.'',').'</td>'//value
       
'<td>'.$milestone[$x][$y][$b++].'</td>'.        //Baseline
       
'<td>'.$milestone[$x][$y][$b++].'</td>'.        //Estimate
       
'<td>'.$milestone[$x][$y][$b++].'</td>'.        //Actual
        
'</tr>';   
  
$a=0;
  
$b=0;
 }
}
echo 
'</table>';
// dispose of result set
mysql_free_result($result);
mysql_free_result($result1);
// close connection to database server
mysql_close($link);
echo 
'</body></html>';
 
?>
dgkindy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to 2D arrays and looping
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11683 seconds with 12 queries