I have two tables that are related to each other. and after I add a row to table 1 I need to add a row to table 2.
Table1 (tblLpcMembers) primary key is LpcMemberID (auto-increment) and I need to get the index number from the insert to use that as the index into table2 (tblMemberCreds).
When I add the row in table1 nothing changes in the grid – I don’t get any errors, but the debug log does show the inserts for table1 and table2.
I am using the setAfterCrudAction method, and I know that if the original insert fails it won’t fire. But since I don’t see any errors I don’t know what’s going on.
Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
<?php require_once '/var/www/llpc.tinicumconservancy.org/public_html/jqSuite/jq-config.php'; // include the jqGrid Class require_once ABSPATH."php/PHPSuito/jqGrid.php"; // include the driver class require_once ABSPATH."php/PHPSuito/DBdrivers/jqGridPdo.php"; // Connection to the server $conn = new PDO(DB_DSN."tinicum",DB_USER,DB_PASSWORD); // Tell the db that we use utf-8 $conn->query("SET NAMES utf8"); // Create the jqGrid instance $grid3 = new jqGridRender($conn); $grid3->debug=true; $grid3->showError = true; // Write the SQL Query $grid3->SelectCommand = " select m.LpcMemberID, m.FirstName, m.LastName, m.Phone, m.eMail, t.LpcDescription as LPC, m.Notes, case when MemberInactive = 0 then 'Active' else 'Inactive' end MemberInactive from tblLpcMembers m, tblLpcType t where m.LPC = t.LpcID"; // Set output format to json $grid3->dataType = 'json'; $grid3->table='tblLpcMembers'; $grid3->setPrimaryKeyID('LpcMemberID'); // Let the grid create the model $grid3->setColModel(); // Set some grid options $grid3->setGridOptions(array( "rowNum"=>40, "rowList"=>array(30,40,50), "sortname"=>"LastName,FirstName", // "sortorder"=>"asc", "hoverrows"=>true, "altRows"=>true, "height"=>"600", "autowidth"=>true, "toppager"=>true, "caption"=>"tblLpcMembers" )); // Set the url from where we obtain the data $grid3->setUrl('tblLpcMembers.php'); // Change some property of the field(s) $grid3->setColProperty("LpcMemberID", array("editable"=>false,"hidden"=>true)); $grid3->setColProperty("FirstName", array("label"=>"First Name", "required"=>true)); $grid3->setColProperty("LastName", array("label"=>"Last Name", "required"=>true)); $grid3->setColProperty("Phone", array("required"=>true)); $grid3->setColProperty("eMail", array("required"=>true)); $grid3->setColProperty("LPC", array("label"=>"LPC Description","editrules"=>array("required"=>true))); $grid3->setColProperty("Notes", array("label"=>"Notes","width"=>"200", "searchoptions"=>array("sopt"=>array('cn','bw','bn','nc')),"edittype"=>"textarea", "editoptions"=>array("rows"=>5, "cols"=>80))); $grid3->setColProperty("MemberInactive", array("label"=>"Active Status","required"=>true)); $cid = jqGridUtils::GetParam('LpcMemberID'); $grid3->setAfterCrudAction("add","insert into tblLpcMemberCreds (LpcMemberID,username,password) values(?,'','')",array($cid)); // Enable filter toolbar searching $grid3->toolbarfilter = true; // Enable operation search $grid3->setFilterOptions(array("searchOperators"=>true)); $grid3->setSelect("LPC", "select LpcID,LpcDescription from tblLpcType order by 2", false, true, false); $grid3->setSelect("MemberInactive", array(0=>'Active',1=>'Inactive'), false, true, false); $grid3->navigator = true; $grid3->setNavOptions('navigator', array("excel"=>false,"add"=>true,"edit"=>true,"del"=>true,"view"=>true, "search"=>true, "cloneToTop"=>true)); $grid3->setNavOptions('edit',array("height"=>"auto","dataheight"=>"auto","width"=>700,"closeAfterEdit"=>true)); $grid3->setNavOptions('add',array("height"=>"auto","dataheight"=>"auto","width"=>"auto","closeAfterAdd"=>true)); $grid3->setNavOptions('view',array("top"=>30,"left"=>30,"height"=>"auto","dataheight"=>"auto","width"=>800,"labelswidth"=>"20%")); //Trigger toolbar with custom button $search = <<<SEARCH jQuery("#searchtoolbar").click(function(){ jQuery('#grid')[0].triggerToolbar(); return false; }); SEARCH; $grid3->setJSCode($search); $txtbx = <<<TB function(formid) { jQuery('#v_Notes').css({'height':'80px','white-space':'break-spaces'}); jQuery('#viewhdgrid3').html('LpcMemberID '+$('#v_LpcMemberID span').html()); } TB; $grid3->setNavEvent('view','beforeShowForm',$txtbx); // Enjoy $grid3->renderGrid('#grid3','#grid3-toppager',true, null, null, true, false); ?> |
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top