Advertisement
Guest User

Untitled

a guest
May 13th, 2011
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. $page = $_GET['page']; // get the requested page
  2. $limit = $_GET['rows']; // get how many rows we want to have into the grid
  3. $sidx = $_GET['sidx']; // get index row - i.e. user click to sort
  4. $sord = $_GET['sord']; // get the direction
  5. if(!$sidx) $sidx =1;
  6. // connect to the database
  7. $db = mysql_connect($dbhost, $dbuser, $dbpassword)
  8. or die("Connection Error: " . mysql_error());
  9.  
  10. mysql_select_db($database) or die("Error conecting to db.");
  11. $result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id");
  12. $row = mysql_fetch_array($result,MYSQL_ASSOC);
  13. $count = $row['count'];
  14.  
  15. if( $count >0 ) {
  16. $total_pages = ceil($count/$limit);
  17. } else {
  18. $total_pages = 0;
  19. }
  20. if ($page > $total_pages) $page=$total_pages;
  21. $start = $limit*$page - $limit; // do not put $limit*($page - 1)
  22. $SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id ORDER BY $sidx $sord LIMIT $start , $limit";
  23. $result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error());
  24.  
  25. $responce->page = $page;
  26. $responce->total = $total_pages;
  27. $responce->records = $count;
  28. $i=0;
  29. while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
  30. $responce->rows[$i]['id']=$row[id];
  31. $responce->rows[$i]['cell']=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row[note]);
  32. $i++;
  33. }
  34. echo json_encode($responce);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement