cari data

Ony · Aug 19, 2013
didalam isi kolom nmkantor ada kantor1, kantor2, kantor3 dst ...
bgmn klo mrnampilkan hanya, semisal kantor2 sj? terimakasih :)
<?php
include '../db.php';

$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'id_atk';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'asc';
$cari = isset($_POST['cari']) ? mysql_real_escape_string($_POST['cari']) : '';

$offset = ($page-1) * $rows;
$where = " WHERE nmkantor LIKE '%$cari%' OR brgatk LIKE '%$cari%' OR tribulan LIKE '%$cari%' OR tahun LIKE '%$cari%' ";
$text = "SELECT * FROM atk $where ORDER BY $sort $order LIMIT $rows OFFSET $offset";
$result = array();
$result[' '] = mysql_num_rows(mysql_query("SELECT * FROM atk $where"));
$row = array();	

$criteria = mysql_query($text);
while($data=mysql_fetch_array($criteria))
{	
	$row[] = array(
		'id_atk' => $data['id_atk'],
		'kdskpd' => $data['kdskpd'],		
		'nmkantor' => $data['nmkantor'],
		'brgatk' => $data['brgatk'],
		'tribulan' => $data['tribulan'],				
		'tahun' => $data['tahun'],		
		'jmlhsaldoawal' => $data['jmlhsaldoawal'],
		'hrgsaldoawal' => $data['hrgsaldoawal'],
		'totalsaldoawal' => $data['totalsaldoawal'],
		'jmlhtambah' => $data['jmlhtambah'],
		'hrgtambah' => $data['hrgtambah'],		
		'totaltambah' => $data['totaltambah'],
		'jmlhkurang' => $data['jmlhkurang'],		
		'jmlhsaldoakhir' => $data['jmlhsaldoakhir'],		
		'hrgsaldoakhir' => $data['hrgsaldoakhir'],		
		'totalsaldoakhir' => $data['totalsaldoakhir']			
	);
}
$result=array_merge($result,array('rows'=>$row));
echo json_encode($result);
?>
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Aug 19, 2013 · 0 Suka · 0 Tidak Suka
coba edit dibagian

$where = " WHERE nmkantor LIKE '%$cari%' OR brgatk LIKE '%$cari%' OR tribulan LIKE '%$cari%' OR tahun LIKE '%$cari%' ";

jadi $where = " WHERE nmkantor ='kantor2' AND (brgatk LIKE '%$cari%' OR tribulan LIKE '%$cari%' OR tahun LIKE '%$cari%') ";
0
Loading...
Ony · Aug 19, 2013 · 0 Suka · 0 Tidak Suka
skrg sdh bisa mas,,, terimakasih atas ilmunya :) :)