Dear mas Ellyx..

Saya mengalami kesulitan untuk menampilkan data dari database..
kasusnya adalah.. di database yang ada datanya itu dimulai dari tanggal 2 s.d 20 Mei misalnya..
saya sudah berhasil menampilkan semua data tersebut..
dan yang saya ingin tanyakan, saya ingin menampilkan dimulai tanggal 1 mei meskipun datanya tidak ada.. tetapi dikasih nilai 0.. sampai dengan tanggal sekarang, misal hari ini tgl 27, jadi yang ditampilkan dari mulai tanggal 1 s.d 27 mei.. dan jika besoknya tanggal 28, maka data akan ditampilkan dimulai tanggal 1 s.d 28.. dst..
berikut coding yang sudah dibuat..
<?php

	include "connection.php";
	$msgcodeid = "1, 2, 8, 12, 13";
	
	
	$query    = "SELECT DATE(datelog) dates, msgcodeid, COUNT(*) AS amount 
				 FROM log_traffic 
				 WHERE msgcodeid in ($msgcodeid) AND oprid = 2 
				 GROUP BY dates, msgcodeid 
				 ORDER BY dates, msgcodeid";
				  
	$result    = mysql_query($query) or die(mysql_error());
	
	
	$prevDate  = "";
	$currDate  = "";
	$amountDay = 0;
	
	
	while($row = mysql_fetch_array($result)) 
	{
          $prevDate = $currDate;
          $currDate = $row[dates];
          $i++;
		
             if ($prevDate != $currDate)
             {
                $amountDay++;
                $dataDay[$amountDay] = $row[dates];
             }

		$dataOut[$currDate][$row[msgcodeid]] = $row[amount];
		
		

	}


	 
	$rightTotal = 0;
	$total1     = 0;
	$total2     = 0;
	$total8     = 0;
	$total12    = 0;
	$total13    = 0;

	for ($i = 1; $i <= $amountDay; $i++)
	{
		$theDate = $dataDay[$i];
		$jml1 = $dataOut[$theDate][1];
		if (strlen($jml1) < 1) $jml1 = 0;
		$total1 = $total1 + $jml1;

		$jml2 = $dataOut[$theDate][2];
		if (strlen($jml2) < 1) $jml2 = 0;
		$total2 = $total2 + $jml2;

		$jml8 = $dataOut[$theDate][8];
		if (strlen($jml8) < 1) $jml8 = 0;
		$total8 = $total8 + $jml8;

		$jml12 = $dataOut[$theDate][12];
		if (strlen($jml12) < 1) $jml12 = 0;
		$total12 = $total12 + $jml12;

		$jml13 = $dataOut[$theDate][13];
		if (strlen($jml13) < 1) $jml13 = 0;
		$total13 = $total13 + $jml13;

		$rightTotal = $jml1 + $jml2 + $jml8 + $jml12 + $jml13;
 
		
		

echo "<tr class=isi bgcolor='".$warna."'>
      <td align=center>$theDate</td>
      <td align=center>".$jml1."</td>
      <td align=center>".$jml2."</td>
      <td align=center>".$jml8."</td>
      <td align=center>".$jml12."</td>
      <td align=center>".$jml13."</td>
      <td align=center>".$rightTotal."</td>
	  </tr>";
   }
echo "<tr>
		<td align=center>TOTAL</td>
		<td align=center>".$total1."</td>
		<td align=center>".$total2."</td>
		<td align=center>".$total8."</td>
		<td align=center>".$total12."</td>
		<td align=center>".$total13."</td>
		<td align=center>".($total1 + $total2 + $total8 + $total12 + $total13)."</td>
	</tr> 
</table>";
?>
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · May 27, 2013 · 0 Suka · 0 Tidak Suka
coba:
<?php
 
	include "connection.php";
	$msgcodeid = "1, 2, 8, 12, 13";
	$startDate = date('Y-m-01');
	$endDate = date('Y-m-d H:i:s');
 
	$query    = "SELECT DATE(datelog) dates, msgcodeid, COUNT(*) AS amount 
				 FROM log_traffic 
				 WHERE msgcodeid in ($msgcodeid) AND oprid = 2
				 and  datelog >= '$startDate' and datelog <= '$endDate'
				 GROUP BY dates, msgcodeid 
				 ORDER BY dates, msgcodeid";
 
	$result    = mysql_query($query) or die(mysql_error());
 
 
	$prevDate  = "";
	$currDate  = "";
	$amountDay = 0;
 
 $dataOut = array();
	while($row = mysql_fetch_array($result)) 
	{
		$dataOut[$row['dates']][$row['msgcodeid']] = $row['amount'];
	}
 
 
 
	$rightTotal = 0;
	$total1     = 0;
	$total2     = 0;
	$total8     = 0;
	$total12    = 0;
	$total13    = 0;
 
	for ($i = 1; $i <= date('d'); $i++)
	{
		$theDate = date('Y-m-').($i < 10 ? '0'.$i : $i);
		if(!isset($dataOut[$theDate])){
			$jml1 = 0;
			$jml2 = 0;
			$jml8 = 0;
			$jml12 = 0;
			$jml13 = 0;
		}else{
			$jml1 = $dataOut[$theDate][1];
			if (strlen($jml1) < 1) $jml1 = 0;
			$total1 = $total1 + $jml1;
	 
			$jml2 = $dataOut[$theDate][2];
			if (strlen($jml2) < 1) $jml2 = 0;
			$total2 = $total2 + $jml2;
	 
			$jml8 = $dataOut[$theDate][8];
			if (strlen($jml8) < 1) $jml8 = 0;
			$total8 = $total8 + $jml8;
	 
			$jml12 = $dataOut[$theDate][12];
			if (strlen($jml12) < 1) $jml12 = 0;
			$total12 = $total12 + $jml12;
	 
			$jml13 = $dataOut[$theDate][13];
			if (strlen($jml13) < 1) $jml13 = 0;
			$total13 = $total13 + $jml13;
 		}
		$rightTotal = $jml1 + $jml2 + $jml8 + $jml12 + $jml13;
 
 
 
 
echo "<tr class=isi bgcolor='".$warna."'>
      <td align=center>$theDate</td>
      <td align=center>".$jml1."</td>
      <td align=center>".$jml2."</td>
      <td align=center>".$jml8."</td>
      <td align=center>".$jml12."</td>
      <td align=center>".$jml13."</td>
      <td align=center>".$rightTotal."</td>
	  </tr>";
   }
echo "<tr>
		<td align=center>TOTAL</td>
		<td align=center>".$total1."</td>
		<td align=center>".$total2."</td>
		<td align=center>".$total8."</td>
		<td align=center>".$total12."</td>
		<td align=center>".$total13."</td>
		<td align=center>".($total1 + $total2 + $total8 + $total12 + $total13)."</td>
	</tr> 
</table>";
?>
0
Loading...
azam · May 27, 2013 · 0 Suka · 0 Tidak Suka
Solved.. Terima kasih banyak mas Ellyx... :)