Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Enrico Rinolfi on Sep 11, 2009 08:18
open dhtmlx forum
Update with data processor

Good Evening,
I've used a sample code of dataprocessor in Grid and all work ok..

I need now to modify update process in order to update records in a table mysql with 2 primary key.

This is the default sample:

function update_row(){
    $sql =     "UPDATE samples_grid SET sales='".$_GET["c0"]."',
                title=        '".addslashes($_GET["c1"])."',
                author=        '".addslashes($_GET["c2"])."',
                price=        '".$_GET["c3"]."',
                instore=    '".$_GET["c4"]."',
                shipping=    '".$_GET["c5"]."',
                bestseller=    '".$_GET["c6"]."',
                pub_date=    '".$_GET["c7"]."'
            WHERE book_id=".$_GET["gr_id"];
    $res = mysql_query($sql);
    
    return "update";    
}

My problem is that i have to pass to value in Where clause like this:

WHERE book_id=".$_GET["gr_id"] AND employee_id=.$_GET["?"];

How can i find the right variable to pass?
Answer posted by Support on Sep 11, 2009 09:55
Which code you are using for data loading in the grid?
Most probably you have something similar to the 

echo '<row id="$book_id">...row related data here ...

which can be changed as
echo '<row id="$book_id"><userdata name="second_id">$employee_id</userdata>...row related data here ...

now , on server side, for each update action you will receive  $_GET["employee_id"] with value of second key.

Answer posted by Enrico Rinolfi on Sep 11, 2009 11:37
Yes the code has been posted on a Knowloedge Base:

<?php
//include db connection settings
//change this setting according to your environment
require_once("config.php");

//include XML Header (as response will be in xml format)
header("Content-type: text/xml");
//encoding may be different in your case
echo('<?xml version="1.0" encoding="iso-8859-1"?>');
//start output of data
echo '<rows id="0">';

//output data from DB as XML
$sql = "SELECT  * from samples_grid";
$res = mysql_query ($sql);
       
if($res){
    while($row=mysql_fetch_array($res)){
        //create xml tag for grid's row
        echo ("<row id='".$row['book_id']."'>");
        print("<cell><![CDATA[".$row['sales']."]]></cell>");
        print("<cell><![CDATA[".$row['title']."]]></cell>");
        print("<cell><![CDATA[".$row['author']."]]></cell>");
        print("<cell><![CDATA[".$row['price']."]]></cell>");
        print("<cell><![CDATA[".$row['instore']."]]></cell>");
        print("<cell><![CDATA[".$row['shipping']."]]></cell>");
        print("<cell><![CDATA[".$row['bestseller']."]]></cell>");
        print("<cell><![CDATA[".gmdate("Y/m/d",strtotime($row['pub_date']))."]]></cell>");
        print("</row>");
    }
}else{
//error occurs
    echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
}

echo '</rows>';

?>

Not understand why grid_id and not book_id because grid_id its not part of mysql table.
after that my last quesion is: what about printing for example a&grave letttres? es:

if i wanted to print in xml content :

print("<cell><![CDATA[".$row['Lunedì']."]]></cell>");
how should be the result code?

thank u for your next 2 answer.







Answer posted by Support on Sep 14, 2009 04:28
//create xml tag for grid's row
echo ("<row id='".$row['book_id']."'>");
print("<userdata name="employee_id">".$row['employee_id']."</userdata>"); //can be added , to have the employee_id on server side
print("<cell><![CDATA[".$row['sales']."]]></cell>");

>>Not understand why grid_id and not book_id because
gr_id is the name of parameter, which contains value of row@id , it doesn't matter what field was used to fill this field.

>> what about printing for example a&grave letttres? es:
There is no any specific requirements from the grid's side, but I'm not quite sure how MySQL handles the names with extended ASCII symbols. ( its fully depends on mysql|php implementation and not related to the grid's functionality ) 
Personally, I suspect that mysql will convert name to valid ASCII, and data will be available as $row['Lunedi'] ( normal i )
Answer posted by Rainolf on Sep 14, 2009 04:49
if($res){
    while($row=mysql_fetch_array($res)){
        //create xml tag for grid's row
        echo ("<row id='".$row['emp_number']."'>");
        echo ("<row id='".$row['book_id']."'>");
        print("<userdata name="employee_id">".$row['employee_id']."</userdata>"); ====> it gives me a syntax error why?
        print("<cell><![CDATA[".$row['sales']."]]></cell>");
        print("<cell><![CDATA[".$row['emp_lastname']."]]></cell>");
        print("<cell><![CDATA[".$row['emp_firstname']."]]></cell>");
        print("<cell><![CDATA[".$row['loc_city']."]]></cell>");
print("</row>");
    }
}else{
//error occurs
    echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
}

echo '</rows>';

?>

Answer posted by Support on Sep 14, 2009 09:01
Sorry , was a my error in the sample code.
It must be 
  print("<userdata name=\"employee_id\">".$row['employee_id']."</userdata>"); //quotes are escaped