Misalkan Data yang ada di tb_hari sbb :
hari_1 hari_2 hari_3 hari_4 hari_5 hari_6
2000-05-01 12000000 5000000 0 0 500000
2000-05-02 0 28000000 180000000 0 500000
2001-05-25 0 28000000 180000000 0 500000
2001-05-26 0 0 120000000 0 0
2001-01-27 5000 8000000 10000000 3000000 1000000
2001-01-28 0 0 0 1500000 50000
2001-01-29 100000 0 0 1500000 0
2002-04-01 500 200 5000 100000 200000
2002-08-02 1500 5200 345000 150000 5200000
2002-11-03 1500 0 0 0 0
Nah, saya mau menampilkan data untuk tahun 2001 saja, untuk codingnya saya buatkan seperti ini :
<?php
require_once( '../opendb.php' );
?>
<link type="text/css" rel="stylesheet" href="../css/my_style.css">
<div class="div-umum">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="6">...:: List Total Pengeluaran Harian ::....</td>
</tr>
<tr>
<td colspan="6">
<form name="list_harian" method="post">
Untuk Tahun : <input type="text" name="txtTahun" size="4" maxlength="4" value="<?=date('Y');?>">
<input type="submit" name="btn_load" value="Load">
</form>
</td>
</tr>
</table>
<?
if ( isset( $_POST['btn_load'] ) ) {
if ($_POST['btn_load'] == 'Load' ) {
$tahun = $_POST['txtTahun'];
$ambil_hari = "SELECT sum(hari_2) as hari01, sum(hari_3) as hari_02, sum(hari_4) as hari_03, sum(hari_5) as hari_04, sum(hari_6) as hari_05 FROM tb_hari WHERE hari_1 '$tahun'";
$hasil_hari = mysql_query($ambil_hari);
$data_hari = mysql_fetch_array( $hasil_hari );
$hari_2 = $data_hari['hari_01'];
$hari_3 = $data_hari['hari_02'];
$hari_4 = $data_hari['hari_03'];
$hari_5 = $data_hari['hari_04'];
$hari_6 = $data_hari['hari_05'];
$total_hari += $hari_2 + $hari_3+ $hari_4 + $hari_5 + $hari_6;
?>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="5">Total Pengeluaran Harian</td>
</tr>
<tr>
<td>Hari 01 <?=$hari_2;?></td>
<td>Hari 02 <?=$hari_3;?></td>
<td>Hari 03 <?=$hari_4;?></td>
<td>Hari 04 <?=$hari_5;?></td>
<td>Hari 05 <?=$hari_6;?></td>
</tr>
<tr>
<td colspan="5">Total Pengeluaran Harian untuk Tahun <?=$tahun;?> Rp : <?=$total_hari;?> </td>
</tr>
</table>
</div>
<?
}
}
?>
Namun ada kesalahan pada : $data_hari = mysql_fetch_array( $hasil_hari );
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in Bla .. bla.. bla ...
Mohon bantuannya Mas ...