Advertisement
dropbox1349

post2.php - flexigrid

Mar 4th, 2015
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.25 KB | None | 0 0
  1. <?
  2. error_reporting(0);
  3. function runSQL($rsql) {
  4.     $hostname = "localhost";
  5.     $username = "root";
  6.     $password = "";
  7.     $dbname   = "country";
  8.     $connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
  9.     mysql_set_charset('utf8',$connect);
  10.     $db = mysql_select_db($dbname);
  11.     $result = mysql_query($rsql) or die ('test');
  12.     return $result;
  13.     mysql_close($connect);
  14. }
  15.  
  16. function countRec($fname,$tname,$where) {
  17. $sql = "SELECT count($fname) FROM $tname $where";
  18. $result = runSQL($sql);
  19. while ($row = mysql_fetch_array($result)) {
  20. return $row[0];
  21. }
  22. }
  23. $page = $_POST['page'];
  24. $rp = $_POST['rp'];
  25. $sortname = $_POST['sortname'];
  26. $sortorder = $_POST['sortorder'];
  27.  
  28. if (!$sortname) $sortname = 'name';
  29. if (!$sortorder) $sortorder = 'desc';
  30.         if($_POST['query']!=''){
  31.             $where = "WHERE `".$_POST['qtype']."` LIKE '%".$_POST['query']."%' ";
  32.         } else {
  33.             $where ='';
  34.         }
  35.         if($_POST['letter_pressed']!=''){
  36.             $where = "WHERE `".$_POST['qtype']."` LIKE '".$_POST['letter_pressed']."%' ";  
  37.         }
  38.         if($_POST['letter_pressed']=='#'){
  39.             $where = "WHERE `".$_POST['qtype']."` REGEXP '[[:digit:]]' ";
  40.         }
  41. $sort = "ORDER BY $sortname $sortorder";
  42.  
  43. if (!$page) $page = 1;
  44. if (!$rp) $rp = 10;
  45.  
  46. $start = (($page-1) * $rp);
  47.  
  48. $limit = "LIMIT $start, $rp";
  49.  
  50. $sql = "SELECT id,iso,name,printable_name,iso3,numcode,extra FROM country $where $sort $limit";
  51. $result = runSQL($sql);
  52.  
  53. $total = countRec('iso','country',$where);
  54.  
  55. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
  56. header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
  57. header("Cache-Control: no-cache, must-revalidate" );
  58. header("Pragma: no-cache" );
  59. header("Content-type: text/x-json");
  60. $json = "";
  61. $json .= "{\n";
  62. $json .= "page: $page,\n";
  63. $json .= "total: $total,\n";
  64. $json .= "rows: [";
  65. $rc = false;
  66. while ($row = mysql_fetch_array($result)) {
  67. if ($rc) $json .= ",";
  68. $json .= "\n{";
  69. $json .= "id:'".$row['id']."',";
  70. $json .= "cell:['".$row['id']."','".$row['iso']."'";
  71. $json .= ",'".addslashes($row['name'])."'";
  72. $json .= ",'".addslashes($row['printable_name'])."'";
  73. $json .= ",'".addslashes($row['iso3'])."'";
  74. $json .= ",'".addslashes($row['numcode'])."']";
  75.  
  76. $json .= "}";
  77. $rc = true;
  78. }
  79. $json .= "]\n";
  80. $json .= "}";
  81. echo $json;
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement