Forum


I cant get the results... Is there any problem with my json php file?
<?php
include("ayar.php");
// coment the above lines if php 5
include("JSON.php");
$json = new Services_JSON();
// end comment
$examp = $_REQUEST["q"]; //query number
$page = $_REQUEST['page']; // get the requested page
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort
$sord = $_REQUEST['sord']; // get the direction
if(!$sidx) $sidx =1;
// search options
// IMPORTANT NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// this type of constructing is not recommendet
// it is only for demonstration
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$wh = "";
$searchOn = Strip($_REQUEST['_search']);
if($searchOn=='true') {
$fld = Strip($_REQUEST['searchField']);
if( $fld=='id' || $fld =='tarih' || $fld=='havuz' || $fld=='giren' || $fld=='cikan' || $fld=='ortalama' || $fld=='aciklama' ) {
$fldata = Strip($_REQUEST['searchString']);
$foper = Strip($_REQUEST['searchOper']);
// costruct where
$wh .= " AND ".$fld;
switch ($foper) {
case "bw":
$fldata .= "%";
$wh .= " LIKE '".$fldata."'";
break;
case "eq":
if(is_numeric($fldata)) {
$wh .= " = ".$fldata;
} else {
$wh .= " = '".$fldata."'";
}
break;
case "ne":
if(is_numeric($fldata)) {
$wh .= " <> ".$fldata;
} else {
$wh .= " <> '".$fldata."'";
}
break;
case "lt":
if(is_numeric($fldata)) {
$wh .= " < ".$fldata;
} else {
$wh .= " < '".$fldata."'";
}
break;
case "le":
if(is_numeric($fldata)) {
$wh .= " <= ".$fldata;
} else {
$wh .= " <= '".$fldata."'";
}
break;
case "gt":
if(is_numeric($fldata)) {
$wh .= " > ".$fldata;
} else {
$wh .= " > '".$fldata."'";
}
break;
case "ge":
if(is_numeric($fldata)) {
$wh .= " >= ".$fldata;
} else {
$wh .= " >= '".$fldata."'";
}
break;
case "ew":
$wh .= " LIKE '%".$fldata."'";
break;
case "ew":
$wh .= " LIKE '%".$fldata."%'";
break;
default :
$wh = "";
}
}
}
//echo $fld." : ".$wh;
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());
mysql_select_db($database) or die("Error conecting to db.");
switch ($examp) {
case 1:
$result = mysql_query("SELECT COUNT(*) AS count, SUM(giren) AS giren, SUM(cikan) AS cikan, SUM(ortalama) AS ortalama FROM balik_hareket".$wh);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;
$SQL = "SELECT * FROM balik_hareket".$wh." ORDER BY ".$sidx." ". $sord." LIMIT ".$start." , ".$limit;
$result = mysql_query( $SQL ) or die("Couldnt execute query.".mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]['id']=$row[id];
$responce->rows[$i]['cell']=array($row[id],$row[havuz],$row[tarih],$row[giren],$row[cikan],$row[ortalama],$row[aciklama]);
$i++;
}
echo json_encode($responce);
break;
case 2:
$result = mysql_query("SELECT COUNT(*) AS count FROM balik_hareket".$wh);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;
$SQL = "SELECT * FROM balik_hareket".$wh." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
$result = mysql_query( $SQL ) or die("Could not execute query.".mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]['id']=$row[id];
$responce->rows[$i]['cell']=array($row[id],$row[tarih],$row[havuz],$row[giren],$row[cikan],$row[ortalama],$row[aciklama]);
$i++;
}
//echo $json->encode($responce); // coment if php 5
echo json_encode($responce);
break;
case 3:
$result = mysql_query("SELECT COUNT(*) AS count FROM balik_hareket".$wh);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;
$SQL = "SELECT * FROM balik_hareket".$wh." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
$result = mysql_query( $SQL ) or die("Couldnt execute query.".mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]['id']=$row[id];
$responce->rows[$i]['cell']=array("",$row[id],$row[tarih],$row[havuz],$row[giren],$row[cikan],$row[ortalama],$row[aciklama]);
$i++;
}
echo $json->encode($responce); // coment if php 5
//echo json_encode($responce);
break;
case 4:
$result = mysql_query("SELECT COUNT(*) AS count FROM balik_hareket".$wh);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;
$SQL = "SELECT * FROM balik_hareket".$wh." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
$result = mysql_query( $SQL ) or die("Couldnt execute query.".mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]=$row;
$i++;
}
//echo $json->encode($responce); // coment if php 5
echo json_encode($responce);
break;
case 5:
$result = mysql_query("SELECT COUNT(*) AS count FROM balik_hareket".$wh);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;
$SQL = "SELECT * FROM balik_hareket".$wh." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
$result = mysql_query( $SQL ) or die("Couldt execute query.".mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]=$responce->rows[$i]['cell']=array($row[id],$row[tarih],$row[havuz],$row[giren],$row[cikan],$row[ortalama],$row[aciklama]);
$i++;
}
//echo $json->encode($responce); // coment if php 5
echo json_encode($responce);
break;
}
mysql_close($db);
function Strip($value)
{
if(get_magic_quotes_gpc() != 0)
{
if(is_array($value))
if ( array_is_associative($value) )
{
foreach( $value as $k=>$v)
$tmp_val[$k] = stripslashes($v);
$value = $tmp_val;
}
else
for($j = 0; $j < sizeof($value); $j++)
$value[$j] = stripslashes($value[$j]);
else
$value = stripslashes($value);
}
return $value;
}
function array_is_associative ($array)
{
if ( is_array($array) && ! empty($array) )
{
for ( $iterator = count($array) - 1; $iterator; $iterator-- )
{
if ( ! array_key_exists($iterator, $array) ) { return true; }
}
return ! array_key_exists(0, $array);
}
return false;
}
?>
04:22

Moderators
30/10/2007

Hello,
maybe you should check your script - also try first without jqGrid - what is
the result? The reasons could be 1001.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
I saw on documentation that:
Description
This method uses colModel names and url parameters from jqGrid
Calling: jQuery("#grid_id").searchGrid( options );
So, when I did that is it replaced url for search?
jQuery(document).ready(function(){
function pickdates(id){
jQuery("#"+id+"_tarih","#rowed3").datepicker({dateFormat:"yy-mm-dd"});}
var lastsel;
jQuery("#rowed3").jqGrid({
url:'get.php',
datatype: "json",
colNames:['Id','Havuz','Tarih', 'Giren', 'Çıkan','Ortalama','Açıklama'],
colModel:[
{name:'id',index:'id', width:40, align:"center"},
{name:'havuz',index:'havuz', width:90, align:"center", editable:true},
{name:'tarih',index:'tarih', width:90, align:"center", editable:true, sorttype:"date"},
{name:'giren',index:'giren', width:90, align:"center", editable:true},
{name:'cikan',index:'cikan', width:90, align:"center", editable:true},
{name:'ortalama',index:'ortalama', width:90, align:"center"},
{name:'aciklama',index:'aciklama', width:250, align:"center", editable:true},
],
rowNum:50,
rowList:[50,100,150],
imgpath: 'themes/sand/images',
pager: jQuery('#prowed3'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
height: 363,
width:800,
caption: "Balık Hareket Tablosu Düzenleme"
}).navGrid('#prowed3', {}, //options
{editCaption: "Kayıt Düzenle", bSubmit: "Kaydet", bCancel: "Vazgeç", processData: "Kaydediyor...", url:"duzenle.php", onInitializeForm: function(formid) {
$("#tarih",formid).datepicker({dateFormat:"dd-mm-yy"});
}}, // edit options
{addCaption: "Kayıt Ekle", bSubmit: "Kaydet", bCancel: "Vazgeç", processData: "Kaydediyor...", url:"ekle.php", onInitializeForm: function(formid) {
$("#tarih",formid).datepicker({dateFormat:"dd-mm-yy"});
}}, // add options
{delCaption: "Kayıt Sil", bSubmit: "Evet", bCancel: "Hayır", processData: "Siliniyor...", url:"sil.php",
msg:"Seçili Kaydın Silinmesini Onaylıyor musunuz?"}, // del options
{sopt:['cn','bw','eq','ne','lt','gt','ew'], url:"arama.php?q=2"} // search options
);
});
06:35

Moderators
30/10/2007

Hello,
The rest of docs says:
When the find button is clicked, jqGrid adds three parameters to the url,
in name=value pairs:
- sField: the 'searchField', the value comes from the index in colModel
- sValue: the 'searchString', the value is the entered value
- sOper: the 'searchOper', the value is the type of search - see sopt array, below
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
78 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66