Expand|Select|Wrap|Line Numbers
- {
- page: 1,
- total: 239,
- rows: [
- {id:'239',cell:['239','ZW','ZIMBABWE','Zimbabwe','ZWE','716']},
- {id:'238',cell:['238','ZM','ZAMBIA','Zambia','ZMB','894']},
- {id:'237',cell:['237','YE','YEMEN','Yemen','YEM','887']},
- {id:'236',cell:['236','EH','WESTERN SAHARA','Western Sahara','ESH','732']},
- {id:'235',cell:['235','WF','WALLIS AND FUTUNA','Wallis and Futuna','WLF','876']},
- {id:'234',cell:['234','VI','VIRGIN ISLANDS, U.S.','Virgin Islands, U.s.','VIR','850']},
- {id:'233',cell:['233','VG','VIRGIN ISLANDS, BRITISH','Virgin Islands, British','VGB','92']},
- {id:'232',cell:['232','VN','VIET NAM','Viet Nam','VNM','704']},
- {id:'231',cell:['231','VE','VENEZUELA','Venezuela','VEN','862']},
- {id:'230',cell:['230','VU','VANUATU','Vanuatu','VUT','548']}]
- }
Expand|Select|Wrap|Line Numbers
- <?
- error_reporting(1);
- function runSQL($rsql) {
- $hostname = "localhost";
- $username = "root";
- $password = "root";
- $dbname = "hms1";
- $connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
- $db = mysql_select_db($dbname);
- $result = mysql_query($rsql) or die ('test');
- return $result;
- mysql_close($connect);
- }
- function countRec($fname,$tname,$where) {
- $sql = "SELECT count($fname) FROM $tname $where";
- $result = runSQL($sql);
- while ($row = mysql_fetch_array($result)) {
- return $row[0];
- }
- }
- $page = $_POST['page'];
- $rp = $_POST['rp'];
- $sortname = $_POST['sortname'];
- $sortorder = $_POST['sortorder'];
- if (!$sortname) $sortname = 'pa_name';
- if (!$sortorder) $sortorder = 'desc';
- if($_POST['query']!=''){
- $where = "WHERE `".$_POST['qtype']."` LIKE '%".$_POST['query']."%' ";
- } else {
- $where ='';
- }
- if($_POST['letter_pressed']!=''){
- $where = "WHERE `".$_POST['qtype']."` LIKE '".$_POST['letter_pressed']."%' ";
- }
- if($_POST['letter_pressed']=='#'){
- $where = "WHERE `".$_POST['qtype']."` REGEXP '[[:digit:]]' ";
- }
- $sort = "ORDER BY $sortname $sortorder";
- if (!$page) $page = 1;
- if (!$rp) $rp = 10;
- $start = (($page-1) * $rp);
- $limit = "LIMIT $start, $rp";
- $sql = "SELECT pa_id,pa_name,pa_pd_patient_id,pa_name FROM patient_appointment $where $sort $limit";
- $result = runSQL($sql);
- $total = countRec('pa_id','patient_appointment',$where);
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
- header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
- header("Cache-Control: no-cache, must-revalidate" );
- header("Pragma: no-cache" );
- header("Content-type: text/x-json");
- $json = "";
- $json .= "{\n";
- $json .= "page: $page,\n";
- $json .= "total: $total,\n";
- $json .= "rows: [";
- $rc = false;
- while ($row = mysql_fetch_array($result)) {
- if ($rc) $json .= ",";
- $json .= "\n{";
- /*$json .= "cell:['".$row['pa_name']."'";
- $json .= ",'".addslashes($row['time'])."'";
- $json .= ",'".addslashes($row['pa_um_id'])."'";
- $json .= ",'".addslashes($row['pa_pd_patient_id'])."']";*/
- $json .= "id:'".$row['pa_id']."',";
- $json .= "cell:['".$row['pa_id']."','".$row['pa_name']."'";
- $json .= ",'".addslashes($row['pa_pd_patient_id'])."']";
- $json .= "}";
- $rc = true;
- }
- $json .= "]\n";
- $json .= "}";
- echo $json;
- ?>
Expand|Select|Wrap|Line Numbers
- $(document).ready(function(){
- $("#flex1").flexigrid
- (
- {
- url: '/public/**post2.ph**p',
- dataType: 'json',
- colModel : [
- {display: 'ID', name : 'id', width : 40, sortable : true, align: 'center'},
- {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'},
- {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'},
- {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'},
- {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true},
- {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'}
- ],
- buttons : [
- {name: 'Add', bclass: 'add', onpress : test},
- {name: 'Delete', bclass: 'delete', onpress : test},
- {separator: true},
- {name: 'A', onpress: sortAlpha},
- ],
- searchitems : [
- {display: 'ISO', name : 'iso'},
- {display: 'Name', name : 'name', isdefault: true}
- ],
- sortname: "id"
- sortorder: "asc",
- usepager: true,
- title: 'Countries',
- useRp: true,
- rp: 10,
- showTableToggleBtn: true,
- width: 700,
- height: 255
- }
- );
- });
i tried out like this also in the views page and the 'hai' is also not getting alerted .
Expand|Select|Wrap|Line Numbers
- $.post("/public/server_processing1.php",{},function(data){
- alert('hai');
- alert(data);
- }, "json");
is there a way to handle json data in zend .