Script telt te veel waarden op
Hij werkt BIJNA goed. De inhoud wordt goed gevuld echter alle bedragen worden bij elkaar opgeteld en niet alleen die van de bewuste regel.
[verwijderd]
Als voorbeeld krijg ik nu al output:
1e regel 2 calc € 7436.67
2e regel 1 calc € 7436.67
De bedragen kunnen niet gelijk zijn. Het zou moeten zijn:
1e regel 2 calc € 5137.24
2e regel 1 calc € 2299.43
Als uiteindelijke totaal kom ik wel op € 7436.67 uit
Plaats alleen relevante code! Precies zoals je doet in latere posts in dit topic...[/modedit]
Gewijzigd op 02/06/2010 22:47:24 door Joren de Wit
Niemand gaat dit doorspitten.
En als je zelf de belangrijke delen eruit vist, dan vind je de fout misschien ook.
De 4e tot de laatste query zou ik kunnen weglaten, zie onderstaande code:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
[code]<?php
//Inhoud
//Query
$sql_i = "SELECT
offerte_order_bev_id,
omschrijving
FROM sp_offerte_order_bev_omschr
WHERE offerte_order_bev_id = '".$row['id']."' ";
if(!$res_i = mysql_query($sql_i,$con))
{
trigger_error(mysql_error().'<br />In query: '.$sql_i);
}
if ($res_i && mysql_num_rows($res_i) >= 1)
{
//Data
while($row_i = mysql_fetch_array($res_i))
{
//Query calcuatie id
$sql_i_c = "SELECT
offerte_order_bev_id,
offerte_order_omsch_id,
calculatie_id
FROM sp_offerte_order_bev_calc
WHERE offerte_order_bev_id = '".$row['id']."' ";
if(!$res_i_c = mysql_query($sql_i_c,$con))
{
trigger_error(mysql_error().'<br />In query: '.$sql_i_c);
}
if ($res_i_c && mysql_num_rows($res_i_c) >= 1)
{
//Data die in dit bericht niet zichtbaar is, zie TS
while($row_i_c = mysql_fetch_array($res_i_c))
{
//Totaal calculatie
$totaal_calc = $bew_totaal_abs + $materiaal_tot + $plaat_tot + $overig_totaal_abs + $flens_tot + $las_tot;
//Subtotaal
$sub_totaal = $sub_totaal + $totaal_calc;
}
}
//Totaal
$totaal = $totaal + $sub_totaal;
$pdf->SetFont("Arial","",8);
$pdf->SetX(15);
$pdf->Cell(150,4,$row_i['omschrijving'],0,0,"L");
$pdf->Cell(20,4,"€ ".number_format($totaal_calc, 2, '.', ''),0,1,"R");
}
}
?>
[code]<?php
//Inhoud
//Query
$sql_i = "SELECT
offerte_order_bev_id,
omschrijving
FROM sp_offerte_order_bev_omschr
WHERE offerte_order_bev_id = '".$row['id']."' ";
if(!$res_i = mysql_query($sql_i,$con))
{
trigger_error(mysql_error().'<br />In query: '.$sql_i);
}
if ($res_i && mysql_num_rows($res_i) >= 1)
{
//Data
while($row_i = mysql_fetch_array($res_i))
{
//Query calcuatie id
$sql_i_c = "SELECT
offerte_order_bev_id,
offerte_order_omsch_id,
calculatie_id
FROM sp_offerte_order_bev_calc
WHERE offerte_order_bev_id = '".$row['id']."' ";
if(!$res_i_c = mysql_query($sql_i_c,$con))
{
trigger_error(mysql_error().'<br />In query: '.$sql_i_c);
}
if ($res_i_c && mysql_num_rows($res_i_c) >= 1)
{
//Data die in dit bericht niet zichtbaar is, zie TS
while($row_i_c = mysql_fetch_array($res_i_c))
{
//Totaal calculatie
$totaal_calc = $bew_totaal_abs + $materiaal_tot + $plaat_tot + $overig_totaal_abs + $flens_tot + $las_tot;
//Subtotaal
$sub_totaal = $sub_totaal + $totaal_calc;
}
}
//Totaal
$totaal = $totaal + $sub_totaal;
$pdf->SetFont("Arial","",8);
$pdf->SetX(15);
$pdf->Cell(150,4,$row_i['omschrijving'],0,0,"L");
$pdf->Cell(20,4,"€ ".number_format($totaal_calc, 2, '.', ''),0,1,"R");
}
}
?>
Gewijzigd op 01/06/2010 21:40:50 door Mui ter
Zie je in dat dit systeem heeel traag is omdat je tot 3 keer toe met alle voorgaande rijen een nieuwe SELECT query maakt? Zoek hier op de site eens naar de joins tutorial, moet een hoop schelen.
Klopt, ik wil eerst weten dat het goed werkt en dan ga ik kijken hoe uj met de JOIN alles aan elkaar kan plakken.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
//Query
$sql_i = "SELECT
offerte_order_bev_id,
omschrijving
FROM sp_offerte_order_bev_omschr
WHERE offerte_order_bev_id = '".$row['id']."' ";
if(!$res_i = mysql_query($sql_i,$con))
{
trigger_error(mysql_error().'<br />In query: '.$sql_i);
}
if ($res_i && mysql_num_rows($res_i) >= 1)
{
//Data
while($row_i = mysql_fetch_array($res_i))
{
$pdf->SetFont("Arial","",8);
$pdf->SetX(15);
$pdf->Cell(145,4,$row_i['omschrijving'],0,0,"L");
$pdf->Ln();
//Query calcuatie id
?>
//Query
$sql_i = "SELECT
offerte_order_bev_id,
omschrijving
FROM sp_offerte_order_bev_omschr
WHERE offerte_order_bev_id = '".$row['id']."' ";
if(!$res_i = mysql_query($sql_i,$con))
{
trigger_error(mysql_error().'<br />In query: '.$sql_i);
}
if ($res_i && mysql_num_rows($res_i) >= 1)
{
//Data
while($row_i = mysql_fetch_array($res_i))
{
$pdf->SetFont("Arial","",8);
$pdf->SetX(15);
$pdf->Cell(145,4,$row_i['omschrijving'],0,0,"L");
$pdf->Ln();
//Query calcuatie id
?>
en
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
//Totaal calculatie
$totaal_calc = $bew_totaal_abs + $materiaal_tot + $plaat_tot + $overig_totaal_abs + $flens_tot + $las_tot;
$pdf->SetX(165);
$pdf->Cell(20,4,"€ ".number_format($totaal_calc, 2, '.', ''),0,1,"R");
$pdf->Ln();
// //Marge
// $marge_perc = $row['marge'];
//
// $marge = $totaal_calc * $marge_perc / 100;
//Subtotaal
$sub_totaal = $sub_totaal + $totaal_calc;
}
}
}
?>
//Totaal calculatie
$totaal_calc = $bew_totaal_abs + $materiaal_tot + $plaat_tot + $overig_totaal_abs + $flens_tot + $las_tot;
$pdf->SetX(165);
$pdf->Cell(20,4,"€ ".number_format($totaal_calc, 2, '.', ''),0,1,"R");
$pdf->Ln();
// //Marge
// $marge_perc = $row['marge'];
//
// $marge = $totaal_calc * $marge_perc / 100;
//Subtotaal
$sub_totaal = $sub_totaal + $totaal_calc;
}
}
}
?>
Dan komt de output al beter in de buurt namelijk:
1e regel 2 calc € 2002.24
€ 5137.24
€ 7436.67
2e regel 1 calc
De € 7436.67 hoort er helemaal niet en de tekst '2e regel 1 calc' moet in lijn staan met € 5137.24.
EDIT
Probleem is opgelost.
Gewijzigd op 03/06/2010 20:49:12 door Mui ter