Author Topic: Load/save data from/to MySQL  (Read 7168 times)

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Load/save data from/to MySQL
« on: January 30, 2014, 03:58:58 pm »
Hi,

I'm loading data to paramquery using an HTML table that is produced with PHP+MySQL.

This is working ok for loading the data but how do I send updates, deletes, creates back to MySQL?

Thanks in advance for your help!

xangvo

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Load/save data from/to MySQL
« Reply #1 on: March 10, 2014, 12:59:14 pm »
Hello everyone,
I'm new with paramquery. I had the same the problem with nuno.nogueira.
But I can get( load) the data from DB to grid. My main problem is I can not update, add, delete a record although I read all topic in the forum for a few day.
If anyone can help me, I would appreciate your help. Thank you in advance! :D
My code in Javascript is:
$(function () {
 var colM = [
        { title: "Id", width: 10, dataType: "float" },
        { title: "Name", width: 450, dataType: "string", align: "left" },
        { title: "Title", width: 450, dataType: "string", align: "left"}
      ];

   var dataModel = {
        location: "remote",//mandatory
        sorting: "local",
        paging: "local",
        dataType: "JSON",
        method: "GET",
        //sortIndx: "name",//effect
        sortDir: "up",
      rPP: 10,
        url: "demos/getCustomers/getCustomers.php", //custom field in dataModel for pqGridCrud
        getData: function (dataJSON) {
            var data = dataJSON.data;
            return { data: dataJSON.data };
        }
    };
   
    var newObj = {
        flexHeight: true,
        flexWidth: true,
        dataModel: dataModel,
        bottomVisible: true,
        colModel: colM,
        selectionModel: { mode: 'single' },
        editable: false,
        scrollModel: { horizontal: false },
        title: "People Page",
        columnBorders: true
    };
      var $grid = $("#grid_crud-remote").pqGridCrud(newObj);
 });

and my code in getCustomers.php is:
?php
$dbserver='localhost';
   $dbusername='root';
   $dbpassword='';
   $dbname='gkeagle';
   
   $db=mysql_connect("$dbserver","$dbusername","$dbpassword");
   $currDb=mysql_selectdb($dbname) or die (mysql_error());
   
   $sqlstring="SELECT * FROM people WHERE 1 ";
      $result=mysql_query($sqlstring) or die (mysql_error());
   $php_total=mysql_num_rows($result);

   $php_var_id=array();
   $php_var_name=array();
   $php_var_title=array();
   while($row=mysql_fetch_array($result))//while($row=mysql_fetch_array($result))
   {
      
      $php_var_id[]=$row['p_id'];
      $php_var_name[]=$row['p_name'];
      $php_var_title[]=$row['p_title'];
      
   }
    $js_var1=json_encode($php_var_id);
    $js_var2=json_encode($php_var_name);
    $js_var3=json_encode($php_var_title);
   
   $json_arr = array('data'=>array(
   array($php_var_id[0],$php_var_name[0],$php_var_title[0]),
   array($php_var_id[1],$php_var_name[1],$php_var_title[1]),
   array($php_var_id[2],$php_var_name[2],$php_var_title[2]),
   array($php_var_id[3],$php_var_name[3],   $php_var_title[3]),
   array($php_var_id[4],$php_var_name[4],$php_var_title[4]),
   array($php_var_id[5],$php_var_name[5],$php_var_title[5]),
   array($php_var_id[6],$php_var_name[6],$php_var_title[6]),
   array($php_var_id[7],$php_var_name[7],$php_var_title[7]),
   array($php_var_id[8],$php_var_name[8],$php_var_title[8]),
   array($php_var_id[9],$php_var_name[9],$php_var_title[9]),
   array($php_var_id[10],$php_var_name[10],$php_var_title[10]),
   array($php_var_id[11],$php_var_name[11],$php_var_title[11])));
$php_json = json_encode($json_arr);
echo $php_json;
?>

I found in pqGridCrud.js and try to get recId but I still cannot update, add, delete record to DB and get them to grid. After I click edit button and update (nothing update to DB), the data in grid disappear when sorting, paging.
If anyone recomend example code for  getCustomers.php for me, I would really appriciate your help!

qmaan

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Load/save data from/to MySQL
« Reply #2 on: June 01, 2014, 02:31:13 pm »
I am not sure you have resolved or not but is an example

http://lvstechnologies.wordpress.com/2013/07/17/pq-grid/