Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

Array problem

The attached script is supposed to build a chart, but it is not and I get this error

Warning: Division by zero in /home/loanmod1/domains/ermqc.com/private_html/include/fpdf/diag.php on line 124

Notice: Array to string conversion in /home/loanmod1/domains/ermqc.com/private_html/include/fpdf/diag.php on line 125

Fatal error: Unsupported operand types in /home/loanmod1/domains/ermqc.com/private_html/include/fpdf/diag.php on line 77

The query is running correctly and does pull data.  The problem (I believe) is that the $value is not in the correct format or am I not associating them correctly?  BarDiagram (Line 14) is looking for results like

$data = array('Assets' => 48, 'Income' => 25, 'Employment' => 10);
$result = mysql_query($allCat) or die(mysql_error());
            while ($row = mysql_fetch_array($result))
            {
            $value[ $row['Cat'] ] = $row['Ct'];
            }
            $data = array ($value);
            $pdf->SetFont('Arial', 'BIU', 12);
            $pdf->Cell(0, 5, '2 - Bar diagram', 0, 1);
            $pdf->Ln(8);
            $valX = $pdf->GetX();
            $valY = $pdf->GetY();
            if ( count( $data ) != 0 ){

            $pdf->BarDiagram (190, 70, $data, '%l : %v (%p)', array(255,175,100));
            $pdf->SetXY($valX, $valY + 80);
            }

Open in new window

0
rcowen00
Asked:
rcowen00
  • 4
  • 3
1 Solution
 
effxCommented:
Try

mysql_fetch_assoc

instead of

mysql_fetch_array
0
 
Ray PaseurCommented:
mysql_fetch_array() creates a superset of the data found in mysql_fetch_assoc() so that may not be the problem.  But if the code is correct, the data base is mis-designed.  In any case, it is a data-dependent problem and we cannot see your data.

Here is how you can visualize the data coming from the data base and know what you've got.  After line 3 add var_dump($row); after line 6 add var_dump($data); you will find the output easier to read if you echo "<pre>" before you call var_dump().  Please do that, and post the output in the code snippet so we can see the data. Then we will be able to suggest a solution based on information instead of speculation!
0
 
rcowen00Author Commented:
Ray, here are the results.  Could you tell me what is mis-designed in the db?  Thank you.
Var_Dump after line 3
 
array(4) { 
[0]=> string(10) "Regulatory" ["Cat"]=> string(10) "Regulatory" [1]=> string(2) "21" ["Ct"]=> string(2) "21" } array(4) { [0]=> string(11) "Application" ["Cat"]=> string(11) "Application" [1]=> string(2) "16" ["Ct"]=> string(2) "16" } array(4) { [0]=> string(17) "Closing Documents" ["Cat"]=> string(17) "Closing Documents" [1]=> string(1) "5" ["Ct"]=> string(1) "5" } array(4) { [0]=> string(4) "HUD1" ["Cat"]=> string(4) "HUD1" [1]=> string(1) "5" ["Ct"]=> string(1) "5" } array(4) { [0]=> string(9) "Insurance" ["Cat"]=> string(9) "Insurance" [1]=> string(1) "3" ["Ct"]=> string(1) "3" } array(4) { [0]=> string(11) "Disclosures" ["Cat"]=> string(11) "Disclosures" [1]=> string(1) "2" ["Ct"]=> string(1) "2" } array(4) { [0]=> string(9) "Appraisal" ["Cat"]=> string(9) "Appraisal" [1]=> string(1) "2" ["Ct"]=> string(1) "2" } array(4) { [0]=> string(6) "Assets" ["Cat"]=> string(6) "Assets" [1]=> string(1) "2" ["Ct"]=> string(1) "2" } array(4) { [0]=> string(8) "Approval" ["Cat"]=> string(8) "Approval" [1]=> string(1) "2" ["Ct"]=> string(1) "2" } array(4) { [0]=> string(14) "Govt Documents" ["Cat"]=> string(14) "Govt Documents" [1]=> string(1) "1" ["Ct"]=> string(1) "1" }

Open in new window


Var_Dump after line 6
bool(false)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Ray PaseurCommented:
Here's that var_dump() output formatted in a way that makes it a little easier to read.  As you can see the numeric indexes are redundant.  You can get rid of those by using mysql_fetch_assoc().  I do not think they are hurting you here, just extra unnecessary stuff.

We need two more data visualizations (note the variable names carefully).  After line 5 var_dump($value); and after line 6 var_dump($data); -- post those here, thanks.
array(4) { 
[0]=> string(10) "Regulatory" 
["Cat"]=> string(10) "Regulatory" 
[1]=> string(2) "21" 
["Ct"]=> string(2) "21" 
} 

array(4) { 
[0]=> string(11) "Application" 
["Cat"]=> string(11) "Application" 
[1]=> string(2) "16" 
["Ct"]=> string(2) "16" 
} 

array(4) { 
[0]=> string(17) "Closing Documents" 
["Cat"]=> string(17) "Closing Documents" 
[1]=> string(1) "5" 
["Ct"]=> string(1) "5" 
} 

array(4) { 
[0]=> string(4) "HUD1" 
["Cat"]=> string(4) "HUD1" 
[1]=> string(1) "5" 
["Ct"]=> string(1) "5" 
} 

array(4) { 
[0]=> string(9) "Insurance" 
["Cat"]=> string(9) "Insurance" 
[1]=> string(1) "3" 
["Ct"]=> string(1) "3" 
} 

array(4) { 
[0]=> string(11) "Disclosures" 
["Cat"]=> string(11) "Disclosures" 
[1]=> string(1) "2" 
["Ct"]=> string(1) "2" 
} 

array(4) { 
[0]=> string(9) "Appraisal" 
["Cat"]=> string(9) "Appraisal" 
[1]=> string(1) "2" 
["Ct"]=> string(1) "2" 
} 

array(4) { 
[0]=> string(6) "Assets" 
["Cat"]=> string(6) "Assets" 
[1]=> string(1) "2" 
["Ct"]=> string(1) "2" 
} 

array(4) { 
[0]=> string(8) "Approval" 
["Cat"]=> string(8) "Approval" 
[1]=> string(1) "2" 
["Ct"]=> string(1) "2" 
} 

array(4) { 
[0]=> string(14) "Govt Documents" 
["Cat"]=> string(14) "Govt Documents" 
[1]=> string(1) "1" 
["Ct"]=> string(1) "1" 
}

Open in new window

0
 
rcowen00Author Commented:
line 5 var_dump($value);

array(10) {
["Regulatory"]=> string(2) "21"
["Application"]=> string(2) "16"
["Closing Documents"]=> string(1) "5"
["HUD1"]=> string(1) "5"
["Insurance"]=> string(1) "3"
["Approval"]=> string(1) "2"
["Disclosures"]=> string(1) "2"
["Appraisal"]=> string(1) "2"
["Assets"]=> string(1) "2"
["Govt Documents"]=> string(1) "1"
}

 line 6 var_dump($data);

array(1) {
[0]=> array(10) {
 ["Regulatory"]=> string(2) "21"
["Application"]=> string(2) "16"
["Closing Documents"]=> string(1) "5"
["HUD1"]=> string(1) "5"
["Insurance"]=> string(1) "3"
["Approval"]=> string(1) "2"
["Disclosures"]=> string(1) "2"
["Appraisal"]=> string(1) "2"
["Assets"]=> string(1) "2"
["Govt Documents"]=> string(1) "1"
} }
0
 
Ray PaseurCommented:
Good.  $value is an associative array.  $data is a numerically indexed array, with one element at [0] that consists of the $value array.  You might try changing line 14 to use $value instead of $data.  While you're at it, change line 12, too.
0
 
rcowen00Author Commented:
That solved that problem.  Thank you Ray.

I am now getting the following when I include lines 57 - 70.  

Warning: Cannot modify header information - headers already sent by (output started at /home/loanmod1/domains/ermqc.com/private_html/include/fpdf/font/courier.php:9) in /home/loanmod1/domains/ermqc.com/private_html/include/fpdf/fpdf.php on line 1017
FPDF error: Some data has already been output, can't send PDF file

<?php
$pdf->Image('../../images/logo_color_tcg.png',0,5,210,20);

$pdf->setXY($pdf->GetX(),$pdf->GetY()+20);
$pdf->SetFont('Arial','B',12);
$pdf->Cell(190,5,$mgmtSummary_TitleRow['branchName'],0,0,'C');
$pdf->Ln(4);
$pdf->Cell(190,5,date('m/d/Y', strtotime($beginDate)).' thru '.date('m/d/Y', strtotime($endDate)),0,0,'C');
$pdf->Ln(15);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(190,5,'All Findings by Category',0,0,'C');
$pdf->Ln(5);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(50);
$pdf->Cell(60, 4, 'Category Name', '','', 'L','1');
$pdf->Line($pdf->GetX(),$pdf->GetY(),$pdf->GetX(),$pdf->GetY()+4);
$pdf->Cell('20', 4, '# Findings','', '', 'L', '1','');
$pdf->Ln(4);
$pdf->Cell(50);
$pdf->Line($pdf->GetX(),$pdf->GetY(),$pdf->GetX()+80,$pdf->GetY());
$allCat="SELECT
    findingCategoryName AS Cat,
    COUNT(loanNumber) AS Ct
FROM loan
JOIN audit USING (loanKey)
JOIN loanFinding USING (auditID)
JOIN finding USING (findingKey)
JOIN findingCategory USING (findingCategoryKey)
JOIN severity stS ON stS.severityKey=loanFinding.stSeverity
LEFT JOIN severity cuS ON cuS.severityKey=loanFinding.customSeverity
WHERE branchKey='$branchKey'
AND loan.active='1'
AND audit.activeStatus='1'
AND loanFinding.active='1'
AND audit.auditTypeKey='$auditTypeKey'
AND audit.trackingDate BETWEEN '$beginDate' AND '$endDate'
GROUP BY findingCategoryName
ORDER BY Count(loanNumber) DESC";


 $allCatList = mysql_query($allCat) or die(mysql_error());
    while ($allCatRow = mysql_fetch_assoc($allCatList))
    {
     $pdf->SetFont('Arial','',8);
    $catName = $allCatRow['Cat'];
    $ct = $allCatRow['Ct'];
$pdf->Line($pdf->GetX(),$pdf->GetY(),$pdf->GetX(),$pdf->GetY()+4);
$pdf->Cell('60', 4,$catName,'', '', 'L', '');
$pdf->Line($pdf->GetX(),$pdf->GetY(),$pdf->GetX(),$pdf->GetY()+4);
$pdf->Cell('20', 4,$ct,'', '', 'C', '');
$pdf->Line($pdf->GetX(),$pdf->GetY(),$pdf->GetX(),$pdf->GetY()+4);
$pdf->Ln(4);
$pdf->Cell(50);
$pdf->Line($pdf->GetX(),$pdf->GetY(),$pdf->GetX()+80,$pdf->GetY());

        }
//            $result = mysql_query($allCat) or die(mysql_error());
//            while ($row = mysql_fetch_assoc($result))
//            {
//            $value[ $row['Cat'] ] = $row['Ct'];
//            }
//            $pdf->SetFont('Arial', 'BIU', 12);
//            $pdf->Cell(0, 5, '2 - Bar diagram', 0, 1);
//            $pdf->Ln(8);
//            $valX = $pdf->GetX();
//            $valY = $pdf->GetY();
//            if ( count( $value ) != 0 ){
//            $pdf->BarDiagram (190, 70, $value, '%l : %v (%p)', array(255,175,100));
//            $pdf->SetXY($valX, $valY + 80);
//          }
          ?>

Open in new window

0
 
Ray PaseurCommented:
Well, that is apparently a very different issue.  It is a law of HTTP that all headers must come first and be complete before any browser output at all, even invisible whitespace.  So you would want to examine the logic and look at the lines identified in the error messages to see what is producing browser output before FPDF tries to send the header.

A common cause of this situation is an error message sent by some included class or function.

Another cause is something like this.   Because of starting and stopping PHP on two different lines, there is an invisible end-of-line character between these two PHP scripts.

<?php include ('common.php'); ?>
<?php header("Location: /"); ?>

A common workaround is to add ob_start() to the top of the main script.
http://php.net/manual/en/function.ob-start.php
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now