title: jqGrid : "All in One" approach width jqGridEdit Class > how to set a composite primary key?
body: <p>How to set a composite primary key for a "All in One" approach (grid defined in JS file, and data using jqGridEdit Class in php file) ?
  Please, for me a composite primary key of a table T, is a elementary primary key that is defined with some fields belong to this table T !</p>
  
  <p>Here is my test, but i get no data and cannot use the CRUD operations : </p>
  
  <ul>
  <li><p>In my JS file i have this lines code:</p>
  
  <pre><code>...
  colModel:[
     {name:"index",index:"index",label:"index"}, // &lt;= THAT'S JUST THE INDEX OF MY TABLE         
     {name:"user",index:"user",label:"user",key:true}, // &lt;= A PART OF MY COMPOSITE PRIMARY KEY
     {name:"pwd",index:"pwd",label:"pwd",key:true},    // &lt;= A PART OF MY COMPOSITE PRIMARY KEY
     {name:"state",index:"state",label:"state",key:true}, // &lt;= A PART OF MY COMPOSITE PRIMARY KEY
     ... &lt;= AND SO ON
     url:"mygrid_crud.php",
     datatype:"json",
     jsonReader:{repeatitems:false},
     editurl: "mygrid_crud.php",
     prmNames:{"id":"index"} // &lt;= WHAT I NEED TO WRITE HERE ???
    ...
  </code></pre></li>
  <li><p>In my php file (mygrid_crud.php) :</p>
  
  <pre><code>...
  $grid = new jqGridEdit($conn);
  $query = "SELECT * FROM mytable WHERE user='$user' and pwd='$pwd' and state='$state'..."; // &lt;= SELECT * it's ok or i need to specify all fields i need ? 
  $grid-&gt;SelectCommand = $query;
  $grid-&gt;dataType = "json";
  $grid-&gt;table = 'mytable';
  $grid-&gt;setPrimaryKeyId('index'); // &lt;= WHAT I NEED TO WRITE HERE ???
  ...
  $grid-&gt;editGrid();
  </code></pre></li>
  </ul>
  
  <p>Please, say me what is wrong, and how to do to set a composite primary key in this approach !?</p>
  
  <p>Thank you so much for tour responses.</p>
  
  <hr>
  
  <p>So, here is the solution i get after a lot of efforts ;-( </p>
  
  <p>It's maybe not the optimal solution, but add, edit and dell operations work well !!!</p>
  
  <p>Here is an example of a table definition with a COMPOSITE PRIMARY KEY :</p>
  
  <pre><code>CREATE TABLE `chat` (
    `number` int(11) NOT NULL AUTO_INCREMENT,
  
    `user` varchar(30) NOT NULL,
    `pwd` varchar(100) NOT NULL,
    `subject` varchar(100) NOT NULL,
    `time` datetime NOT NULL,
    `recipient` varchar(100) NOT NULL,
  
    `message` varchar(1000) DEFAULT NULL,
  
    PRIMARY KEY (`user`, `pwd`, `subject`, `time`, `recipient`),
    UNIQUE KEY `number` (`number`)
  ) 
  </code></pre>
  
  <p>So to manage such table with a grid, i do as follows.</p>
  
  <p>In my HTML file, i have this lines of code :</p>
  
  <pre><code>...
  &lt;table id='grid_chat'&gt;&lt;/table&gt;
  &lt;div id='pager_chat'&gt;&lt;/div&gt;
  ...
  </code></pre>
  
  <p>And in my PHP file, i have this lines of code :</p>
  
  <pre><code> ...
  $grid = new jqGridRender($conn);
  …
  if($oper=="edit"){…}
  elseif($oper=="del"){…}
  …
  $grid-&gt;setPrimaryKeyId('number');
  …
  // here i get the primary key for the new message i want to add 
  $chat = $_SESSION["chat"];
  $user = $chat["user"];
  $pwd = $chat["pwd"];
  $subject = $chat["subject"];
  …
  $query = "SELECT * FROM chat WHERE user='$user' and pwd='$pwd' and subject='$subject'...”;
  $grid-&gt;SelectCommand = $query;
  …
  // for the UNIQUE KEY (used for edit and dell operations)
  $grid-&gt;setColProperty("number", array("hidden"=&gt;true)); 
  
  // for the COMPOSITE PRIMARY KEY (used for add operation)
  $grid-&gt;setColProperty("user", array("hidden"=&gt;true,"editoptions"=&gt;array("value"=&gt; $user),"editrules"=&gt;array("required"=&gt;true)));
  $grid-&gt;setColProperty("pwd", array("hidden"=&gt;true,"editoptions"=&gt;array("value"=&gt; $pwd),"editrules"=&gt;array("required"=&gt;true)));
  $grid-&gt;setColProperty("subject", array("hidden"=&gt;true,"editoptions"=&gt;array("value"=&gt; $subject),"editrules"=&gt;array("required"=&gt;true)));
  $grid-&gt;setColProperty("time", array("hidden"=&gt;true,"editoptions"=&gt;array("value"=&gt; $time),"editrules"=&gt;array("required"=&gt;true)));
  $grid-&gt;setColProperty("recipient", array("hidden"=&gt;true,"editoptions"=&gt;array("value"=&gt; $recipient),"editrules"=&gt;array("required"=&gt;true)));
  
  // for the message
  $grid-&gt;setColProperty("message", array("classes"=&gt;"multiligne","label"=&gt;"Message","width"=&gt;400,"edittype"=&gt;"textarea","editrules"=&gt;array("required"=&gt;true)));
  
  // Set a new user datetime format using PHP convensions (for the php time variable)
  $grid-&gt;setUserTime('Y-m-d H:i:s');
  …
  </code></pre>
  
  <p>It's not the "All in One" approach, but it works well !!</p>
  
  <p>If somebody see something to optimize, please tell me back !!!</p>
  
  <p>Regards,</p>
  
  <p>Qualliarys</p>