Solved

Missing first record

Posted on 2013-12-20
2
312 Views
Last Modified: 2013-12-20
Hi Experts,

In my page I query my database twice and the page works just fine but it only shows the query results starting from the second record.

When I query the database using same query in MyPHPadmin I do get the first record. But not in this page.

Hope you van help me...


<?
require_once('../includes/config.php');
access_control();
toegang("60","0");
define('EURO',chr(128));
?>
<html>
<head>
<title>Verstuurde facturen per jaar/kwartaal</title>
<link rel='stylesheet' href='../tree1.css'>
<link rel="stylesheet" href="tabber.css" TYPE="text/css" MEDIA="screen">
<script type="text/javascript" src="tabber.js"></script>
<?
function date_quarter()
{
    $month = date('n');
    if ($month <= 3) return 1;
    if ($month <= 6) return 2;
    if ($month <= 9) return 3;
    return 4;
}
$date = date("Y-m-d"); 
$huidigjaar = date("Y", strtotime($date));
$huidigkwartaal = date_quarter();$min10 = $huidigjaar-10;$min9 = $huidigjaar-9;$min8 = $huidigjaar-8;$min7 = $huidigjaar-7;$min6 = $huidigjaar-6;
$min5 = $huidigjaar-5;
$min4 = $huidigjaar-4;
$min3 = $huidigjaar-3;
$min2 = $huidigjaar-2;
$min1 = $huidigjaar-1;
$jaren = array ($min10, $min9, $min8, $min7, $min6, $min5, $min4, $min3, $min2, $min1, $huidigjaar);
$kwartalen = array(1,2,3,4);
?>
<h3 align="center">Verstuurde facturen per jaar/kwartaal</h3>
<p align="center"><input type=button onClick="location='../verkeersplein.php'" value='Terug'></p>
<div class="tabber" id="tab1">
<?
$i=1;
foreach ($jaren as $jaar) {
	If ($jaar > "2011"){
	If ($huidigjaar==$jaar) {
		echo"<div class=\"tabbertab tabbertabdefault\">";
	}else{
		echo "<div class=\"tabbertab\">";
	}
		echo "<h2><a name=\"tab".$i."\">".$jaar."</a></h2>";
		If($jaar=="2012"){echo"<p>In 2012 zijn we in kwartaal vier begonnen met het gebruik van deze applicatie daarom is alleen dit kwartaal weergegeven.</p>";}
		echo "<div class=\"tabber\" id=\"tab".$i."-1\">";
			foreach ($kwartalen as $kwartaal) {
				If($jaar=="2012"){$kwartaal=4;} 
				If ($huidigkwartaal==$kwartaal) {
					echo"<div class=\"tabbertab tabbertabdefault\">";
				}else{
					echo "<div class=\"tabbertab\">";
				}
					if ($kwartaal==1){ $start=$jaar."-01-01"; $stop=$jaar."-03-31";}
					if ($kwartaal==2){ $start=$jaar."-04-01"; $stop=$jaar."-06-30";}
					if ($kwartaal==3){ $start=$jaar."-07-01"; $stop=$jaar."-09-30";}
					if ($kwartaal==4){ $start=$jaar."-10-01"; $stop=$jaar."-12-31";}
					$sql1 = "SELECT sponsor_facturen.*, sponsor_klanten.naam FROM sponsor_facturen INNER JOIN sponsor_klanten ON sponsor_facturen.klantID=sponsor_klanten.id WHERE  sponsor_facturen.type = 'factuur' AND (sponsor_facturen.aangemaakt between '".$start."' AND '".$stop."') AND sponsor_klanten.type='B' order by sponsor_facturen.betaald, sponsor_klanten.naam";
					$result1 = mysql_query($sql1);
					$row1 = mysql_fetch_array($result1);
					$num1 = mysql_num_rows($result1);
					
					$sql2 = "SELECT sponsor_facturen.*, sponsor_klanten.naam FROM sponsor_facturen INNER JOIN sponsor_klanten ON sponsor_facturen.klantID=sponsor_klanten.id WHERE sponsor_facturen.type = 'factuur' AND (sponsor_facturen.aangemaakt between '".$start."' AND '".$stop."') AND sponsor_klanten.type='P' order by sponsor_facturen.betaald, sponsor_klanten.naam ";
					$result2 = mysql_query($sql2);
					$row2 = mysql_fetch_array($result2);
					$num2 = mysql_num_rows($result2);
					
					$aantal = $num1+$num2;
					echo "<h3>".$kwartaal."e kwartaal (".$aantal.")</h3>";
					$startdate = new DateTime($start); 
					$stopdate = new DateTime($stop); 
					$startdatum = date_format ( $startdate, 'd-m-Y' );
					$stopdatum = date_format ( $stopdate, 'd-m-Y' );
					echo "<p>Dit kwartaal van loopt van ".$startdatum." tot ".$stopdatum.".</p>";
					if ($num1 >'0'){
						$carreturn = "\r\n";
						echo '<table border=0 align="center">';
						echo '<tr><td>factuur</td><td><b>nr.</b></td><td><b>factuurdatum</b></td><td><b>periode van</b></td><td><b>periode tot</b></td><td><b>Sponsor</b></td><td><b>netto bedrag</b></td><td><b>BTW</b></td><td><b>bruto bedrag</b></td><td><b>betaald</b></td></tr>';
						$i="";
						$netto = '0';
						$BTW = '0';
						$bruto = '0';
						$nettotot = '0';
						$BTWtot = '0';
						$brutotot = '0';
						$onbetaaldnettotot = '0';
						$onbetaaldBTWtot = '0';
						$onbetaaldbrutotot = '0';
						$betaaldnettotot = '0';
						$betaaldBTWtot = '0';
						$betaaldbrutotot = '0';
						$i=0;
						while ($row1 = mysql_fetch_array($result1)) { 
						$i++;
						if($i&1) {
							echo "<tr class='odd'>"; 
						} else {
							echo "<tr class='even'>";
						}
						$aangemaakt = new DateTime($row1['aangemaakt']); 
						$aangemaakt = date_format ( $aangemaakt, 'd-m-Y' );
						$van = new DateTime($row1['van']); 
						$van = date_format ( $van, 'd-m-Y' );
						$tot = new DateTime($row1['tot']); 
						$tot = date_format ( $tot, 'd-m-Y' );
						$herinnerdatum = new DateTime($row1['herinnerdatum']); 
						$herinnerdatum = date_format ( $herinnerdatum, 'd-m-Y' );
						$netto= number_format($row1['netto'], 2, ',', '.');
						$BTW= number_format($row1['BTW'], 2, ',', '.');
						$bruto= number_format($row1['bruto'], 2, ',', '.');
						If($row1['betaald']=='0000-00-00'){
							$betaald = 'nee ';
							$onbetaaldnettotot = $onbetaaldnettotot+$row1['netto'];
							$onbetaaldBTWtot = $onbetaaldBTWtot+$row1['BTW'];
							$onbetaaldbrutotot = $onbetaaldbrutotot+$row1['bruto'];
							}else{
							$betaald = 'ja ';
							$betaaldnettotot = $betaaldnettotot+$row1['netto'];
							$betaaldBTWtot = $betaaldBTWtot+$row1['BTW'];
							$betaaldbrutotot = $betaaldbrutotot+$row1['bruto'];
						}
						echo "<td align=\"center\"><a href=\"facturen/{$row1['bestandsnaam']}\" TARGET=\"_blank\"><img border=0 src='../images/pdf.gif'></a></td><td>".$row1['factuurnummer']."</td><td width=\"100\" align=\"center\">".$aangemaakt."</td><td width=\"100\">". $van."</td><td width=\"100\">". $tot."</td><td>". $row1['naam']."</td><td align=\"right\">". $netto."</td><td align=\"right\">". $BTW."</td><td align=\"right\">". $bruto."</td><td align=\"center\">". $betaald."</td></tr>";
						$nettotot = $nettotot+$row1['netto'];
						$BTWtot = $BTWtot+$row1['BTW'];
						$brutotot = $brutotot+$row1['bruto'];
						}
						$nettotot= number_format($nettotot, 2, ',', '.');
						$BTWtot= number_format($BTWtot, 2, ',', '.');
						$brutotot= number_format($brutotot, 2, ',', '.');
						$onbetaaldnettotot= number_format($onbetaaldnettotot, 2, ',', '.');
						$onbetaaldBTWtot= number_format($onbetaaldBTWtot, 2, ',', '.');
						$onbetaaldbrutotot= number_format($onbetaaldbrutotot, 2, ',', '.');
						$betaaldnettotot= number_format($betaaldnettotot, 2, ',', '.');
						$betaaldBTWtot= number_format($betaaldBTWtot, 2, ',', '.');
						$betaaldbrutotot= number_format($betaaldbrutotot, 2, ',', '.');
						echo "<tr><td colspan=\"14\"><hr></td></tr>";
						echo "<tr><td></td><td></td><td align=\"center\"></td><td></td><td></td><td align=\"right\"><b>Totalen onbetaald :</B></td><td width=\"80\" align=\"right\"><b>".EURO.$onbetaaldnettotot."</b></td><td width=\"80\" align=\"right\"><b>".EURO.$onbetaaldBTWtot."</b></td><td width=\"80\" align=\"right\"><b>".EURO.$onbetaaldbrutotot."</b></td><td></td><td></td><td></td></tr>";
						echo "<tr><td></td><td></td><td align=\"center\"></td><td></td><td></td><td align=\"right\"><b>Totalen betaald :</B></td><td width=\"80\" align=\"right\"><b>".EURO.$betaaldnettotot."</b></td><td width=\"80\" align=\"right\"><b>".EURO.$betaaldBTWtot."</b></td><td width=\"80\" align=\"right\"><b>".EURO.$betaaldbrutotot."</b></td><td></td><td></td><td></td></tr>";
						echo "<tr><td></td><td></td><td align=\"center\"></td><td></td><td></td><td align=\"right\"><b>Totaal te innen:</B></td><td width=\"80\" align=\"right\"><b>".EURO.$nettotot."</b></td><td width=\"80\" align=\"right\"><b>".EURO.$BTWtot."</b></td><td width=\"80\" align=\"right\"><b>".EURO.$brutotot."</b></td><td></td><td></td><td></td></tr>";

						ECHO "</table>";
						} ELSE {
						if ($num2<>'0'){
							echo "<p>In dit kwartaal zijn geen facturen verzonden naar bedrijven.</p>";
						}
					}
					
					ECHO "<h3 align=\"center\">Verstuurde facturen naar particulieren</h3>";
					if ($row2 >'0'){
						$carreturn = "\r\n";
						echo '<table border=0 align="center">';
						echo '<tr><td>factuur</td><td><b>factuur nr.</b></td><td><b>factuurdatum</b></td><td><b>periode van</b></td><td><b>periode tot</b></td><td><b>Sponsor</b></td><td><b>bedrag</b></td><td><b>betaald</b></td></tr>';
						$i="";
						$netto = '0';
						$BTW = '0';
						$bruto = '0';
						$nettotot = '0';
						$BTWtot = '0';
						$brutotot = '0';
						$onbetaaldbrutotot ='0';
						$betaaldbrutotot ='0';
						while ($row2 = mysql_fetch_array($result2)) { 
						$i++;

						if($i&1) {
							echo "<tr class='odd'>"; 
						} else {
							echo "<tr class='even'>";
						}
						$aangemaakt = new DateTime($row2['aangemaakt']); 
						$aangemaakt = date_format ( $aangemaakt, 'd-m-Y' );
						$van = new DateTime($row2['van']); 
						$van = date_format ( $van, 'd-m-Y' );
						$tot = new DateTime($row2['tot']); 
						$tot = date_format ( $tot, 'd-m-Y' );
						$herinnerdatum = new DateTime($row2['herinnerdatum']); 
						$herinnerdatum = date_format ( $herinnerdatum, 'd-m-Y' );
						$netto= number_format($row2['netto'], 2, ',', '.');
						$BTW= number_format($row2['BTW'], 2, ',', '.');
						$bruto= number_format($row2['bruto'], 2, ',', '.');
						If($row2['betaald']=='0000-00-00'){
							$betaald = 'nee ';
							$onbetaaldbrutotot = $onbetaaldbrutotot+$row2['bruto'];
						}else{
							$betaald = 'ja ';
							$betaaldbrutotot = $betaaldbrutotot+$row2['bruto'];
						}
						echo "<td align=\"center\"><a href=\"facturen/{$row2['bestandsnaam']}\" TARGET=\"_blank\"><img border=0 src='../images/pdf.gif'></a></td><td>".$row2['factuurnummer']."</td><td width=\"100\" align=\"center\">".$aangemaakt."</td><td width=\"100\">". $van."</td><td width=\"100\">". $tot."</td><td>". $row2['naam']."</td><td align=\"right\">". $bruto."</td><td align=\"center\">".$betaald."</td></tr>";
						$nettotot = $nettotot+$row2['netto'];
						}
						$brutotot= number_format($nettotot, 2, ',', '.');
						$onbetaaldbrutotot= number_format($onbetaaldbrutotot, 2, ',', '.');
						$betaaldbrutotot= number_format($betaaldbrutotot, 2, ',', '.');
						echo "<tr><td colspan=\"13\"><hr></td></tr>";
						echo "<tr><td></td><td></td><td align=\"center\"></td><td></td><td></td><td align=\"right\"><b>Totalen onbetaald:</B></td><td width=\"80\" align=\"right\"><b>".EURO.$onbetaaldbrutotot."</b></td><td></td><td></td><td></td></tr>";
						echo "<tr><td></td><td></td><td align=\"center\"></td><td></td><td></td><td align=\"right\"><b>Totalen betaald:</B></td><td width=\"80\" align=\"right\"><b>".EURO.$betaaldbrutotot."</b></td><td></td><td></td><td></td></tr>";
						echo "<tr><td></td><td></td><td align=\"center\"></td><td></td><td></td><td align=\"right\"><b>Totaal te innen:</B></td><td width=\"80\" align=\"right\"><b>".EURO.$brutotot."</b></td><td></td><td></td><td></td></tr>";
						echo "</table>";
					} ELSE {
						if ($num1<>'0'){
							echo "<p>In dit kwartaal zijn geen facturen verzonden naar particulieren.</p>";
						} else {
							echo "<p>In dit kwartaal zijn geen facturen verzonden.</p>";
						}
					}
				echo "</div>";
				If($jaar=="2012"){break;} 
			}
			
		echo "</div>";
	echo "</div>";	
$i=$i+1;
}  
} 
echo "</div>";
?> 
</body>
</html>

Open in new window

0
Comment
Question by:Steynsk
2 Comments
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39731512
One line 61 and 66 you have this:

$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);


The mysql_fetch_array() command pulls the next available record and moves the record pointer on, so by the time you want to loop through your records with the while() loop you are already on record 2 - remove those lines and it'll work fine.
0
 
LVL 1

Author Closing Comment

by:Steynsk
ID: 39731561
Thanks for finding it.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

756 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