Jump to content

no idea what went wrong


scarezekiel

Recommended Posts

okay so i have this problem i dont know how to fix it..

 

 

 

my 1st query runs well..but the 2nd query doesnt work..

 

 

on the 2nd query for year 2009..the answer should be 61.28 while the other 100..

 

it shows the same answer as year 2001..

 

how do i fix this..

 

 

 




<?php require("html2fpdf.php"); 

$server = 'localhost';
$username = '';
$password = '';
$database_name='';

$dbconn = mysql_connect($server, $username,$password,false) or die("Could not establish connection");

mysql_select_db($database_name, $dbconn) or die ("Could not select database");

if (!$dbconn) {
    die('Something went wrong while connecting to MSSQL');
}


ob_start(); ?>




<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
  <title></title>
  <h5 align="center"><U>KRETAM HOLDINGS BERHAD (168285-H)</U></h5>
  <h4 align="left">List-Field</h4>
</head>
<body>
<table style="text-align: left; width: 715px; height: 32px;"
border="1" cellpadding="2" cellspacing="2">
  <tbody>
    <tr>
    </tr>
    <tr>
      <th style="font-style: italic;">Field No</th>
      <th style="font-style: italic;">Ex Field No</th>
      <th style="font-style: italic;">Planting Year</th>
      <th style="font-style: italic;">Land Utilities</th>
      <th style="font-style: italic;">Field Hectares</th>
      <th style="font-style: italic;">Annual Total</th>
      <th style="font-style: italic;">Total Hectares</th>
      <br />      
    </tr>
   <tr>
      <th>Mature</th>                                    
      <br />      
    </tr>
        
    

<?

$query="SELECT tblfield.*, annualtotal,annualrowcount  FROM tblfield
	left join vwfield_annualtotal_location on vwfield_annualtotal_location.locationid = tblfield.locationid
	and vwfield_annualtotal_location.type = tblfield.type
	and vwfield_annualtotal_location.plantingyear = tblfield.plantingyear
        WHERE tblfield.type='mature'
        ORDER BY tblfield.statementyear, tblfield.type desc, tblfield.plantingyear";

        $result=mysql_query($query);
$grandtotalhec=0;
$i = 1;
while($row=mysql_fetch_array($result)) {

    echo $_POST["selection"]; 
$fieldno = $row['fieldno'];
$exfieldno = $row['exfieldno'];
    $plantingyear = $row['plantingyear'];
    $statementyear = $row['statementyear'];
    $fieldhectares = $row['fieldhectares'];
    $annualrowcount = $row['annualrowcount'];
        
    if ($i==$annualrowcount)
    {
    $annualtotal = $row['annualtotal'];
   	$i =1;
    }
    else 
    {
    $annualtotal = '';
    $i =$i + 1;
    }
    end;
    
    $totalhectares = $row['totalhectares'];
echo "<tr><td align='center'>$fieldno</td>";
echo "<td align='center'>$exfieldno</td></tr>";
echo "<td align='center'>$plantingyear</td></tr>";
echo "<td align='center'></td></tr>";
echo "<td align='center'>$fieldhectares</td></tr>";
echo "<td align='center'>$annualtotal</td></tr>";
  
//$query="SELECT plantingyear, locationid, SUM(fieldhectares) AS annualtotal
//FROM tblfield WHERE type='mature' AND locationid='4' AND plantingyear='$plantingyear' GROUP BY locationid, plantingyear";
      //  $result=mysql_query($query);

//while($row=mysql_fetch_array($result)) {  
  
  //$totalhectares = $row['annualtotal'];
  echo "<td align='center'>$totalhectares</td></tr>";
$grandtotalhec = $grandtotalhec + $fieldhectares;

}echo "<tr>";
        echo "<th>Immature</th>";
        echo "<td></td>";	
        echo "<td></td>";
        echo "<td></td>";
        echo "<td></td>";
        echo "<td></td>";				
        echo "<td></td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td></td>";
        echo "<td></td>";
        echo "<td></td>";
        echo "<td></td>";
        echo "<td></td>";
        echo "<td></td>";					
	echo "<td align='center'>".$grandtotalhec."</td>";
echo "</tr>";	

$query="SELECT tblfield.*, annualtotal,annualrowcount  FROM tblfield
	left join vwfield_annualtotal_location on vwfield_annualtotal_location.locationid = tblfield.locationid
	and vwfield_annualtotal_location.type = tblfield.type
	and vwfield_annualtotal_location.plantingyear = tblfield.plantingyear
        WHERE tblfield.type='immature'
        ORDER BY tblfield.statementyear, tblfield.type desc, tblfield.plantingyear";

        $result=mysql_query($query);
$grandtotalhec2=0;
$i = 1;
while($row=mysql_fetch_array($result)) {
    echo $_POST["selection"]; 
$fieldno = $row['fieldno'];
$exfieldno = $row['exfieldno'];
    $type = $row['type'];
    $plantingyear = $row['plantingyear'];
    $statementyear = $row['statementyear'];
    $fieldhectares = $row['fieldhectares'];
    $totalhectares = $row['totalhectares'];
echo "<tr><td align='center'>$fieldno</td>";
echo "<td align='center'>$exfieldno</td></tr>";
echo "<td align='center'>$plantingyear</td></tr>";
echo "<td align='center'></td></tr>";
echo "<td align='center'>$fieldhectares</td></tr>";
echo "<td align='center'>$annualtotal</td></tr>";
echo "<td align='center'>$totalhectares</td></tr>";
$grandtotalhec2 = $grandtotalhec2 + $fieldhectares;
}
echo "<tr>";
        echo "<td></td>";
        echo "<td></td>";	
        echo "<td></td>";			
        echo "<td></td>";
        echo "<td></td>";
        echo "<td></td>";			
        echo "<td align='center'>$grandtotalhec2</td>";			

echo "</tr>";
    
    $query="SELECT * FROM tblfield
        ORDER BY statementyear, type desc, plantingyear";
        $result=mysql_query($query);
$grandtotalhec3=0;
while($row=mysql_fetch_array($result)) {
    echo $_POST["selection"]; 
    $fieldhectares = $row['fieldhectares'];
$grandtotalhec3 = $grandtotalhec3 + $fieldhectares;
}
echo "<tr>";
        echo "<td></td>";
        echo "<td></td>";	
        echo "<td></td>";		
     	
        echo "<td></td>";
        echo "<td></td>";	        
        echo "<td align='center'>Grandtotal</td>";		
        echo "<td align='center'>$grandtotalhec3</td>";			

echo "</tr>";		
?>



</tbody>
</table><h4 align="left">List-Land Utilities</h4>
<table style="text-align: left; width: 715px; height: 32px;"
border="1" cellpadding="2" cellspacing="2">
</tbody>
<tr>
    </tr>
    <tr>
      <th align="left" style="font-style: italic;">Description</th>
      <th style="font-style: italic;">Statement Year</th>
      <th style="font-style: italic;">Land Hectares</th>   
      <th style="font-style: italic;">Total Hectares</th>     
    </tr>

<?
$query="SELECT * FROM tbllandutilities";
        $result=mysql_query($query);
       	$grandtotallandhec4=0;
while($row=mysql_fetch_array($result)) { 
$description = $row['description'];
        $statementyear = $row['statementyear'];
$landhectares = $row['landhectares']; 
    $totalhectares = $row['totalhectares'];  
echo "<tr><td>$description</td>";
echo "<td align='center'>$statementyear</td></tr>";
echo "<td align='center'>$landhectares</td></tr>";
echo "<td>$totalhectares</td></tr>";
$grandtotalhec4 = $grandtotalhec4 + $landhectares;
}
echo "<tr>";
        echo "<td></td>";
        echo "<td></td>";	
        echo "<td></td>";	
        echo "<td align='center'>$grandtotalhec4</td>";					
echo "</tr>";	
?>
  </tbody>
</table>
<br>
</body>
</html>




<?php $var = ob_get_clean(); 


$pdf = new HTML2FPDF('P', 'mm', 'Letter'); 
		$pdf->AddPage(); 
		$pdf->WriteHTML($var); 
		$pdf->Output('test.pdf', 'I');

?>

post-131669-13482403592926_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/264144-no-idea-what-went-wrong/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.