Advertisement
gridphp

Database Table CRUD Grid - outdated

Feb 25th, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. <?php
  2. /**
  3.  * PHP Grid Component
  4.  *
  5.  * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
  6.  * @version 1.4.8
  7.  * @license: see license.txt included in package
  8.  */
  9.  
  10. // set up DB
  11. $conn = mysql_connect("localhost", "root", "");
  12. mysql_select_db("griddemo");
  13. mysql_query("SET NAMES 'utf8'");
  14.  
  15. session_start();
  16.  
  17. // preserve selection for ajax call
  18. if (!empty($_POST["tables"]))
  19. {
  20.     $_SESSION["tab"] = $_POST["tables"];
  21.     $tab = $_SESSION["tab"];
  22. }
  23.  
  24. // update on ajax call
  25. if (!empty($_GET["grid_id"]))
  26.     $tab = $_SESSION["tab"];
  27.  
  28. if (!empty($tab))
  29. {
  30.     // include and create object
  31.     $base_path = "../../lib/";
  32.     include($base_path."inc/jqgrid_dist.php");
  33.     $g = new jqgrid();
  34.  
  35.     // set few params
  36.     $grid["caption"] = "Grid for '$tab'";
  37.     $grid["autowidth"] = true;
  38.     $g->set_options($grid);
  39.  
  40.     // set database table for CRUD operations
  41.     $g->table = $tab;
  42.  
  43.     // render grid
  44.     $out = $g->render("list1");
  45. }
  46. ?>
  47. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  48. <html>
  49. <head>
  50.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>  
  51.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link> 
  52.    
  53.     <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  54.     <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  55.     <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
  56.     <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  57. </head>
  58. <body>
  59.     <form method="post">
  60.         <fieldset>
  61.         <legend>Database Tables</legend>
  62.         Select: <select name="tables">
  63.         <?php
  64.             $q = mysql_query('SHOW TABLES');
  65.             while($rs = mysql_fetch_array($q))
  66.             {
  67.                 $sel = (($rs[0] == $_POST["tables"])?"selected":"");
  68.             ?>
  69.                 <option <?php echo $sel?>><?php echo $rs[0]?></option>
  70.             <?php
  71.             }
  72.         ?>
  73.         </select>
  74.         <input type="submit" value="Load Table">
  75.         </fieldset>
  76.     </form>
  77.     <br>
  78.     <fieldset>
  79.         <?php echo $out?>
  80.     </fieldset>
  81. </body>
  82. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement