kgrogers

Forum Replies Created

Viewing 15 replies - 1 through 15 (of 35 total)
  • Author
    Replies
  • in reply to: Custom Search Form for Pivot Grid #128130
    kgrogers
    Participant

    Oh, I see – The ContactDate field in the pivot table is just text, so that’s why the ‘between’ oper didn’t work.  I changed the oper to ‘bw’ (begins with) and pass the year from the drop-down and it works perfectly.

     

    All done!  Thanks again for your help.

     

    Ken

    • This reply was modified 2 months, 1 week ago by kgrogers. Reason: figured out the problem with using the search operator 'bt'
    in reply to: Custom Search Form for Pivot Grid #128129
    kgrogers
    Participant

    Based on your demo and comments I modified my scripts and incorporated the function in your demo.  That is almost working 100% – I just have one part that doesn’t seem to be working.

     

    I added a ‘between’ search for the ContactDate comlum and it doesn’t seem to be working.

     

    Here is my updated code. Any suggestions are appreciated.

    index.php

    <?php
        include "sqlPDO.php";
        $db = opendb('MySQL','tinicum');
        
        $sql = "
            select LpcDescription
            from tblLpcType
            order by LpcID";
        $LPChtml = array();
        foreach ($db->query($sql) as $row) {
            $LPChtml[strval($row['LpcDescription'])] = $row['LpcDescription'];
        }
        
        $sql = "
            select distinct year(ContactDate) year
            from tblContactNotes
            where year(ContactDate) > 0
            order by 1";
        $Yearhtml = array();
        foreach ($db->query($sql) as $row) {
            $Yearhtml[strval($row['year'])] = $row['year'];
        }
        
        $sql = "
            select distinct month(ContactDate) monthnum,
                   date_format(ContactDate,'%M') monthname               
            from tblContactNotes
            where month(ContactDate) > 0
            order by 1";
        $Monthhtml = array();
        foreach ($db->query($sql) as $row) {
            $Monthhtml[strval($row['monthnum'])] = $row['monthname'];
        }
    
    
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <title>Contact Notes</title>
            <link rel="stylesheet" type="text/css" media="screen" href="/jqSuite/css/jquery-ui.css" />
            <link rel="stylesheet" type="text/css" media="screen" href="/jqSuite/css/trirand/ui.jqgrid.css" />
            <link rel="stylesheet" type="text/css" media="screen" href="/jqSuite/css/ui.multiselect.css" />
            <link rel="stylesheet" type="text/css" media="screen" href="/css/mtabs.css" />
            <style type="text">
                html, body {
                    margin: 0;            /* Remove body margin/padding */
                    padding: 0;
                    overflow: hidden;    /* Remove scroll bars on browser window */
                    font-size: 100%;
                }
                .ui-jqgrid {
                    font-size: 14px;
                }
                .ui-jqgrid .ui-jqgrid-btable tbody tr.jqgrow td {
                    white-space: normal !important;
                    height: auto;
                }
                .mylongdata {
                    height: 190px;
                    overflow-y: auto;
                }
    
            </style>
            <script src="/jqSuite/js/jquery.min.js" type="text/javascript"></script>
            <script src="/jqSuite/js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
            <script src="/jqSuite/js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script>
            <!-- Files for the export ---------------------->
            <script type="text/javascript" language="javascript" src="/js/pivotExport/pdfmake.min.js"></script>
            <script type="text/javascript" language="javascript" src="/js/pivotExport/vfs_fonts.js"></script>
            <script type="text/javascript" language="javascript" src="/js/pivotExport/jszip.min.js"></script>
            <script type="text/javascript">         
                $.jgrid.no_legacy_api = true;
                $.jgrid.useJSON = true;
                $.jgrid.defaults.width = "700";
            </script>
            <script src="/jqSuite/js/jquery-ui.min.js" type="text/javascript"></script>
            <script>
                var LPChtml = <?php print(json_encode($LPChtml)); ?>;
                var Yearhtml = <?php print(json_encode($Yearhtml)); ?>;
                var Monthhtml = <?php print(json_encode($Monthhtml)); ?>;
                var postData = '';
                $(document).ready(function(){                
                    $.each(LPChtml, function(val, text) {
                        // console.log("val: "+val+" text: "+text);
                        $('#LPC').append($("<option></option>").attr("value",val).text(text));
                    });
    
                    $.each(Yearhtml, function(val, text) {
                        // console.log("val: "+val+" text: "+text);
                        $('#year').append($("<option></option>").attr("value",val).text(text));
                    });
    
                    $.each(Monthhtml, function(val, text) {
                        // console.log("val: "+val+" text: "+text);
                        $('#month').append($("<option></option>").attr("value",val).text(text));
                    });
    /***************************************************************************************************************************************/
                    function buildCustomSearch( rule_arr, group ){
                        if(group === undefined) {
                            group = "AND";
                        }
                        var ruleGroup = "";
                        if(Array.isArray(rule_arr) && rule_arr.length) 
                        {
                            ruleGroup = "{\"groupOp\":\"" + group + "\",\"rules\":[";
                            var gi=0;
                            $.each(rule_arr,function(i,n){
                                if (gi > 0) {ruleGroup += ",";}
                                ruleGroup += "{\"field\":\"" + n.name + "\",";
                                ruleGroup += "\"op\":\"" + n.oper + "\",";
                                ruleGroup += "\"data\":\"" + n.val.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
                                gi++;
                            });
                            ruleGroup += "]}";
                            console.log(ruleGroup);
                        }
                        return ruleGroup;
                    }
                    var grid = $("#grid12");
                    $("#do_search").on('click',function(){
                        // console.log("Search was clicked - val is "+$("#year").val());
                        if ($('#Year') != '%') {
                            ys = $('#year').val()+"-01-01";
                            ye = $('#year').val()+"-12-31";
                        }
                        // console.log(ys+"..."+ye);
                        var my_fld=[]; 
                        /*
                        *opts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni','bw', 'bn', 'ew', 'en', 'cn', 'nc'],
                        */
                        my_fld.push({ 
                            name: "LpcDescription", 
                            val : $("#LPC").val(), 
                            oper:"eq"
                        });
                        my_fld.push({
                            name: "ContactDate",
                            val: ys+"..."+ye,
                            oper: "bt"
                        });
                        // console.log(my_fld);
                        var rule = buildCustomSearch( my_fld, "AND");
                        grid.setGridParam({postData:{filters:rule}, search:true}).trigger("reloadGrid");
                    });
    /***************************************************************************************************************************************/
                });
            </script>
        </head>
        <body>
            
    <form action="#"> <label for="LPC">LPC:</label> <select id="LPC" name="LPC"> <option value='%'>All</option> </select> <label for="year">Year:</label> <select id="year" name="year"> <option value='%'>All</option> </select> <label for="year">Month:</label> <select id="month" name="month"> <option value='%'>All</option> </select> <input id="do_search" type="button" value="Search"></input> </form> <br />
    <?php include("leaderboard.php"); ?> </body> </html>

    leaderboard.php

    <?php
        @session_start();
        require_once '/var/www/llpc.tinicumconservancy.org/public_html/jqSuite/jq-config.php';
        require_once '/var/www/llpc.tinicumconservancy.org/public_html/jqSuite/php/PHPSuito/jqPivotGrid.php';
        require_once ABSPATH."php/PHPSuito/DBdrivers/jqGridPdo.php";
        
        // Connection to the server
        $db = new PDO(DB_DSN."tinicum",DB_USER,DB_PASSWORD);
        // Tell the db that we use utf-8
        $db->query("SET NAMES utf8");
    
        $pivot = new jqPivotGrid($db);
        $pivot->SelectCommand = "
            SELECT concat(lm.LastName,', ',lm.FirstName) as ContactedBy,
                lt.LpcDescription,
                lo.LandOwner,
                cn.ContactDate,
                case cn.ContactMode
                    when 1 then 'Phone'
                    when 2 then 'Other'
                    when 3 then 'eMail'
                    when 4 then 'Face to Face'
                    when 5 then 'Mail'
                    when 6 then 'Background'
                    when 7 then 'no contact info'
                    when 8 then 'N/A'
                end as ContactMode,
                count(*) as total
            FROM tblContactNotes cn,
                tblLpcMembers lm,
                tblLandOwners lo,
                tblLpcType lt
            where cn.ContactedBy = lm.LpcMemberID and
                cn.LandOwnerID = lo.LandOwnerID and
                lm.LPC = lt.LpcID
            GROUP BY cn.ContactedBy,
                    cn.LandOwnerID,
                    cn.ContactDate,
                    cn.ContactMode";
        
        $pivot->setData('leaderboard.php');
        $pivot->setGridOptions(array(
            "rowNum"           => 1000,
            "width"            => "auto",
            "height"           => "auto",
            "sortname"         => "ContactDate",
            "sortorder"        => "desc",
            "rowList"          => array(20,40,60,80,1000),
            "altRows"          => true,
            "caption"      => "Leader Board",
            "groupingView" => array("groupCollapse" => true)
        ));
    
    	$pivot->setxDimension(array(
            array(
                "dataName"  => "LpcDescription",
                "width"     => 240),
    		array(
    			"dataName" => "ContactedBy",
    			"width"    => 80),
    		array(
    			"dataName"  => "LandOwner",
    			"width"     => 115),
            array(
                "dataName" => "ContactDate",
                "width"    => 115)
    	));
    	$pivot->setyDimension(array(
    		array(
    			"dataName" => "ContactMode")
    	));
    	$pivot->setaggregates(array(
    		array(
    			"member"      => "total",
    			"aggregator"  => "sum",
    			"width"       => 80,
    			"label"       => "Total",
    			"formatter"   => "integer",
    			"align"       => "right",
    			"summaryType" => "sum")			
    	));
    	$pivot->setPivotOptions(array(
    		"rowTotals" => true,
            "colTotals" => true
    	));
        $pivot->navigator = true;
        $pivot->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"view"=>false,"search"=>true,"reload"=>false));
        $buttonoptions = array(
            "#pager12",array(
                "caption"=>"Csv",
                "title"=>"Local Export to CSV",
                "onClickButton"=>"js: function(){
                    jQuery('#grid12').jqGrid('exportToCsv');
                }"
            )
        );
        $pivot->callGridMethod("#grid12", "navButtonAdd", $buttonoptions,1000);
    
        $buttonoptions = array(
            "#pager12",array(
                "caption"=>"Excel",
                "title"=>"Local Export to Escel",
                "onClickButton"=>"js: function(){
                    jQuery('#grid12').jqGrid('exportToExcel');
                }"
            )
        );
        $pivot->callGridMethod("#grid12", "navButtonAdd", $buttonoptions,500);
        $buttonoptions = array(
            "#pager12", array(
                "caption"=>"Pdf",
                "title"=>"Local Export to PDF",
                "onClickButton"=>"js: function(){
                    jQuery('#grid12').jqGrid('exportToPdf');
                }"
            )
        );
        $pivot->callGridMethod("#grid12", "navButtonAdd", $buttonoptions,500);
    
    	$pivot->renderPivot("#grid12","#pager12", true, null, true, true);
    ?>

     

    in reply to: Custom Search Form for Pivot Grid #128128
    kgrogers
    Participant

    I did see that in your original reply.

     

    I did some testing and it turns out that all of the things I want to filter on aren’t actually in the pivot data – when I initially wrote this I didn’t realize that the initial data was a one-shot thing.

     

    Thanks for the help – I need to go back to the drawing board and come up with a different method to accomplish what I have in mind.

     

    Ken

    in reply to: Custom Search Form for Pivot Grid #128126
    kgrogers
    Participant

    Hi Will:

     

    I must be missing something here. The example you provided is not using PHP, nor is it a pivot table. It looks to me like a straight up javascript only clone of the example on your website for custom search with a PHP grid.

     

    I understand about adding a click event in the index.php file, but I don’t see how that ever would change anything in the leaderboard.php file since it’s not referenced.

     

    Ken

    in reply to: Custom Search Form for Pivot Grid #128123
    kgrogers
    Participant

    Hi Will:

     

    I guess I should have been more specific – and perhaps I posted in the wrong forum too.

    I have a PHP pivotGrid that I want to add filtering to, if that’s possible.

     

    Here is my code:

    index.php

    <?php
        include "sqlPDO.php";
        $db = opendb('MySQL','tinicum');
        
        $sql = "
            select LpcID,
                   concat(LPC,' - ',LpcDescription) as LPC
            from tblLpcType
            order by LpcID";
        $LPChtml = array();
        foreach ($db->query($sql) as $row) {
            $LPChtml[strval($row['LpcID'])] = $row['LPC'];
        }
        
        $sql = "
            select distinct year(ContactDate) year
            from tblContactNotes
            where year(ContactDate) > 0
            order by 1";
        $Yearhtml = array();
        foreach ($db->query($sql) as $row) {
            $Yearhtml[strval($row['year'])] = $row['year'];
        }
        
        $sql = "
            select distinct month(ContactDate) monthnum,
                   date_format(ContactDate,'%M') monthname               
            from tblContactNotes
            where month(ContactDate) > 0
            order by 1";
        $Monthhtml = array();
        foreach ($db->query($sql) as $row) {
            $Monthhtml[strval($row['monthnum'])] = $row['monthname'];
        }
    
    
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <title>Contact Notes</title>
            <link rel="stylesheet" type="text/css" media="screen" href="/jqSuite/css/jquery-ui.css" />
            <link rel="stylesheet" type="text/css" media="screen" href="/jqSuite/css/trirand/ui.jqgrid.css" />
            <link rel="stylesheet" type="text/css" media="screen" href="/jqSuite/css/ui.multiselect.css" />
            <link rel="stylesheet" type="text/css" media="screen" href="/css/mtabs.css" />
            <style type="text">
                html, body {
                    margin: 0;            /* Remove body margin/padding */
                    padding: 0;
                    overflow: hidden;    /* Remove scroll bars on browser window */
                    font-size: 100%;
                }
                .ui-jqgrid {
                    font-size: 14px;
                }
                .ui-jqgrid .ui-jqgrid-btable tbody tr.jqgrow td {
                    white-space: normal !important;
                    height: auto;
                }
                .mylongdata {
                    height: 190px;
                    overflow-y: auto;
                }
    
            </style>
            <script src="/jqSuite/js/jquery.min.js" type="text/javascript"></script>
            <script src="/jqSuite/js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
            <script src="/jqSuite/js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script>
            <!-- Files for the export ---------------------->
            <script type="text/javascript" language="javascript" src="/js/pivotExport/pdfmake.min.js"></script>
            <script type="text/javascript" language="javascript" src="/js/pivotExport/vfs_fonts.js"></script>
            <script type="text/javascript" language="javascript" src="/js/pivotExport/jszip.min.js"></script>
            <script type="text/javascript">         
                $.jgrid.no_legacy_api = true;
                $.jgrid.useJSON = true;
                $.jgrid.defaults.width = "700";
            </script>
            <script src="/jqSuite/js/jquery-ui.min.js" type="text/javascript"></script>
            <script>
                var LPChtml = <?php print(json_encode($LPChtml)); ?>;
                var Yearhtml = <?php print(json_encode($Yearhtml)); ?>;
                var Monthhtml = <?php print(json_encode($Monthhtml)); ?>;
                
                $(document).ready(function(){                
                    $.each(LPChtml, function(val, text) {
                        // console.log("val: "+val+" text: "+text);
                        $('#LPC').append($("<option></option>").attr("value",val).text(text));
                    });
    
                    $.each(Yearhtml, function(val, text) {
                        // console.log("val: "+val+" text: "+text);
                        $('#year').append($("<option></option>").attr("value",val).text(text));
                    });
    
                    $.each(Monthhtml, function(val, text) {
                        // console.log("val: "+val+" text: "+text);
                        $('#month').append($("<option></option>").attr("value",val).text(text));
                    });
                });
            </script>
        </head>
        <body>
    <form action=”#”> <label for=”LPC”>LPC:</label> <select id=”LPC” name=”LPC”> <option value=’%’>All</option> </select> <label for=”year”>Year:</label> <select id=”year” name=”year”> <option value=’%’>All</option> </select> <label for=”year”>Month:</label> <select id=”month” name=”month”> <option value=’%’>All</option> </select> <input id=”search” type=”button” value=”Search”></input> </form> <br />

    <?php include(“leaderboard.php”); ?> </body> </html>

     

    leaderboard.php

    <?php
        @session_start();
        require_once '/var/www/llpc.tinicumconservancy.org/public_html/jqSuite/jq-config.php';
        require_once '/var/www/llpc.tinicumconservancy.org/public_html/jqSuite/php/PHPSuito/jqPivotGrid.php';
        require_once ABSPATH."php/PHPSuito/DBdrivers/jqGridPdo.php";
        
        // Connection to the server
        $db = new PDO(DB_DSN."tinicum",DB_USER,DB_PASSWORD);
        // Tell the db that we use utf-8
        $db->query("SET NAMES utf8");
    
        $pivot = new jqPivotGrid($db);
        $pivot->SelectCommand = "
            SELECT concat(lm.LastName,', ',lm.FirstName) as ContactedBy,
                lo.LandOwner,
                cn.ContactDate,
                case cn.ContactMode
                    when 1 then 'Phone'
                    when 2 then 'Other'
                    when 3 then 'eMail'
                    when 4 then 'Face to Face'
                    when 5 then 'Mail'
                    when 6 then 'Background'
                    when 7 then 'no contact info'
                    when 8 then 'N/A'
                end as ContactMode,
                count(*) as total
            FROM tblContactNotes cn,
                tblLpcMembers lm,
                tblLandOwners lo
            where cn.ContactedBy = lm.LpcMemberID and
                cn.LandOwnerID = lo.LandOwnerID
            GROUP BY cn.ContactedBy,
                    cn.LandOwnerID,
                    cn.ContactDate,
                    cn.ContactMode";
        
        $pivot->setData('leaderboard.php');
        $pivot->setGridOptions(array(
            "rowNum"           => 1000,
            "width"            => "auto",
            "height"           => "auto",
            "sortname"         => "ContactDate",
            "sortorder"        => "desc",
            "rowList"          => array(20,40,60,80,1000),
            "altRows"          => true,
            "caption"      => "Leader Board",
            "groupingView" => array("groupCollapse" => true)
        ));
    
    	$pivot->setxDimension(array(
    		array(
    			"dataName" => "ContactedBy",
    			"width"    => 240),
    		array(
    			"dataName"  => "LandOwner",
    			"width"     => 115),
            array(
                "dataName" => "ContactDate",
                "width"    => 115)
    	));
    	$pivot->setyDimension(array(
    		array(
    			"dataName" => "ContactMode")
    	));
    	$pivot->setaggregates(array(
    		array(
    			"member"      => "total",
    			"aggregator"  => "sum",
    			"width"       => 80,
    			"label"       => "Total",
    			"formatter"   => "integer",
    			"align"       => "right",
    			"summaryType" => "sum")			
    	));
    	$pivot->setPivotOptions(array(
    		"rowTotals" => true,
            "colTotals" => true
    	));
        $pivot->navigator = true;
        $pivot->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"view"=>false,"search"=>false,"reload"=>false));
        $buttonoptions = array(
            "#pager12",array(
                "caption"=>"Csv",
                "title"=>"Local Export to CSV",
                "onClickButton"=>"js: function(){
                    jQuery('#grid12').jqGrid('exportToCsv');
                }"
            )
        );
        $pivot->callGridMethod("#grid12", "navButtonAdd", $buttonoptions,1000);
    
        $buttonoptions = array(
            "#pager12",array(
                "caption"=>"Excel",
                "title"=>"Local Export to Escel",
                "onClickButton"=>"js: function(){
                    jQuery('#grid12').jqGrid('exportToExcel');
                }"
            )
        );
        $pivot->callGridMethod("#grid12", "navButtonAdd", $buttonoptions,500);
        $buttonoptions = array(
            "#pager12", array(
                "caption"=>"Pdf",
                "title"=>"Local Export to PDF",
                "onClickButton"=>"js: function(){
                    jQuery('#grid12').jqGrid('exportToPdf');
                }"
            )
        );
        $pivot->callGridMethod("#grid12", "navButtonAdd", $buttonoptions,500);
    
    	$pivot->renderPivot("#grid12","#pager12", true, null, true, true);
    ?>

     

    • This reply was modified 2 months, 2 weeks ago by kgrogers.
    in reply to: Custom Search Form for Pivot Grid #128121
    kgrogers
    Participant

    I am looking forward to seeing the example!

     

    Ken

    in reply to: Add row to different table after insert #128113
    kgrogers
    Participant

    (For some reason the Code icon is missing from this compose window – sorry in advance for the ugly code block).

     

    I made the changes you suggested:
    <p style=”padding-left: 40px;”>// Set output format to json
    $grid2->dataType = ‘json’;
    $grid2->setTable = ‘tblLandOwners’;
    $grid2->table = ‘tblLandOwners’;
    $grid2->setPrimaryKeyID(‘LandOwnerID’);
    $grid2->serialKey = true;
    if ($grid2->oper == ‘add’) {
        $data = filter_input_array(INPUT_POST);
        $grid2->trans = false;
        if ($grid2->insert($data)) {
            // $sql = “select LAST_INSERT_ID()”;
            // $stmt = $conn->query($sql);
            // $lastInsertID = $stmt->fetch();
            $lastInsertID = $conn->lastInsertId();
            // Create a ‘blank’ record for this landowner in tblParcels
            $sql = “insert into tblParcels (LandOwnerID) values(“.$lastInsertID[0].”)”;
            $conn->query($sql);
        }
    }
    $grid2->add = false;</p>
    <p style=”padding-left: 40px;”>// Let the grid create the model
    $grid2->setColModel();</p>
    The insert for tblLandOwners worked, but no record was created in tblParcels.

    Ken

    in reply to: Add row to different table after insert #128111
    kgrogers
    Participant
     show create table tblLandOwners\G
    *************************** 1. row ***************************
           Table: tblLandOwners
    Create Table: CREATE TABLE tblLandOwners (
      LandOwnerID int(4) NOT NULL AUTO_INCREMENT,
      CurrentlyAssignedTo int(4) NOT NULL DEFAULT 38,
      LandOwner varchar(220) DEFAULT NULL,
      LandOwnerNotes varchar(4044) DEFAULT NULL,
      Status tinyint(2) NOT NULL,
      LandOwnerAddress1 varchar(220) DEFAULT NULL,
      LandOwnerAddress2 varchar(220) DEFAULT NULL,
      LandOwnerCity varchar(220) DEFAULT NULL,
      LandOwnerState varchar(220) DEFAULT NULL,
      LandOwnerZip varchar(220) DEFAULT NULL,
      HowToContact varchar(255) DEFAULT NULL,
      MailingSalutation varchar(220) DEFAULT NULL,
      AddressedTo varchar(220) DEFAULT NULL,
      PRIMARY KEY (LandOwnerID),
      KEY CurrentlyAssignedTo (CurrentlyAssignedTo),
      KEY Status (Status),
      CONSTRAINT tblLandOwners_ibfk_1 FOREIGN KEY (Status) REFERENCES tblLandOwnerStatus (StatusID) ON UPDATE CASCADE
    ) ENGINE=InnoDB AUTO_INCREMENT=169 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci ROW_FORMAT=COMPACT
    1 row in set (0.018 sec)

     

    And just for completeness – here’s tblParcels

    show create table tblParcels\G
    *************************** 1. row ***************************
           Table: tblParcels
    Create Table: CREATE TABLE tblParcels (
      ParcelID int(4) NOT NULL AUTO_INCREMENT,
      LandOwnerID int(4) DEFAULT NULL,
      WatershedID int(4) NOT NULL DEFAULT 9,
      DeededTo varchar(220) DEFAULT NULL,
      ParcelNum varchar(220) NOT NULL DEFAULT '00-000-000',
      Acres decimal(8,4) DEFAULT 0.0000,
      ContiguousParcels int(1) NOT NULL DEFAULT 0,
      GasLease int(1) NOT NULL DEFAULT 0,
      DisqualifyingUses int(1) NOT NULL DEFAULT 0,
      LandUse int(2) NOT NULL DEFAULT 10,
      ParcelRoadNum varchar(220) DEFAULT NULL,
      ParcelRoad varchar(220) DEFAULT NULL,
      ParcelCity varchar(220) DEFAULT NULL,
      ParcelState varchar(220) DEFAULT NULL,
      ParcelZip varchar(220) DEFAULT NULL,
      LPC int(1) NOT NULL DEFAULT 6,
      PRIMARY KEY (ParcelID),
      KEY LandOwnerID (LandOwnerID),
      KEY WatershedID (WatershedID),
      KEY LandUse (LandUse),
      CONSTRAINT tblParcels_ibfk_2 FOREIGN KEY (WatershedID) REFERENCES tblWatersheds (WatershedID) ON DELETE CASCADE ON UPDATE CASCADE,
      CONSTRAINT tblParcels_ibfk_3 FOREIGN KEY (LandUse) REFERENCES tblLandUses (LandUseID) ON UPDATE CASCADE,
      CONSTRAINT tblParcels_ibfk_4 FOREIGN KEY (LandOwnerID) REFERENCES tblLandOwners (LandOwnerID) ON DELETE SET NULL ON UPDATE CASCADE
    ) ENGINE=InnoDB AUTO_INCREMENT=238 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci ROW_FORMAT=COMPACT
    1 row in set (0.000 sec)
    

    I did manage to find a workaround that actually worked. Rather than using the $grid->getLastInsertId() method, I used the MySQL LAST_INSERT_ID() function:

    // Set output format to json
    $grid2->dataType = 'json';
    $grid2->setTable = 'tblLandOwners';
    $grid2->table = 'tblLandOwners';
    $grid2->setPrimaryKeyID('LandOwnerID');
    $grid2->serialKey = true;
    if ($grid2->oper == 'add') {
        $data = filter_input_array(INPUT_POST);
        if ($grid2->insert($data)) {
            $sql = "select LAST_INSERT_ID()";
            $stmt = $conn->query($sql);
            $lastInsertID = $stmt->fetch();
            //$lastInsertID = $grid2->getLastInsertId();
            // Create a 'blank' record for this landowner in tblParcels
            $sql = "insert into tblParcels (LandOwnerID) values(".$lastInsertID[0].")";
            $conn->query($sql);
        }
    }
    $grid2->add = false;
    
    // Let the grid create the model
    $grid2->setColModel();
    

     

    That worked like a champ.

     

    Ken

    in reply to: Add row to different table after insert #128109
    kgrogers
    Participant

    I added some test code based on what you said, but I never get any value with the $grid->getLastInsertId method.

     

    Here’s what I added:

    // Set output format to json
    $grid2->dataType = 'json';
    $grid2->setTable = 'tblLandOwners';
    $grid2->table = 'tblLandOwners';
    $grid2->setPrimaryKeyID('LandOwnerID');
    $grid2->serialKey = true;
    $lastInsertID = "none set";
    if ($grid2->oper == 'add') {
        $fh = fopen('/tmp/addloform.txt','w');
        $data = filter_input_array(INPUT_POST);
        fwrite($fh,"Data: ".print_r($data,true)."\n");
        if ($grid2->insert($data)) {
            $lastInsertID = $grid2->getLastInsertId();
            fwrite($fh,"Last insert LandOwnerID: ".$lastInsertID."\n");
            fclose($fh);
        }
    }
    $grid2->add = false;
    
    // Let the grid create the model
    $grid2->setColModel();
    

    After I perform the insert, the text file I created (addloform.txt) contains:

    Data: Array
    (
    [LandOwnerID] =>
    [LandOwner] => Rogers, K&T
    [LandOwnerNotes] => jj
    [Status] => 1
    [CurrentlyAssignedTo] => 26
    [LandOwnerAddress1] => 86 Gruiver Rd
    [LandOwnerAddress2] =>
    [LandOwnerCity] => Branchburg
    [LandOwnerState] => NJ
    [LandOwnerZip] => 08876
    [HowToContact] => kjh
    [MailingSalutation] => lkjh
    [AddressedTo] => lkjh
    [oper] => add
    )

    Last insert LandOwnerID:

    It looks like the $grid->getLastInsertId method is returning something (since the value got reset from “none set”), but it’s not the primary key from the insert.

     

    The Help file for this method reads:

    The method return the last inserted id when a add is performed and the primary key is serial. In order to have effect this method should be called after renderGrid, editGrid or insert methods – see below

    API Tags:
    Access: public

    Is it possible I have it in the wrong place?

    Ken

    in reply to: Cloning Pager to Top Loses Number of Pages #128103
    kgrogers
    Participant

    Hi Will

     

    If you could send that to me I’d appreciate it.

     

    Do you have a target date for the next release?

     

    Ken

    in reply to: Add row to different table after insert #128099
    kgrogers
    Participant

    Thank you Will – I will give that a try.

     

    Ken

    in reply to: Add row to different table after insert #128096
    kgrogers
    Participant

    I did a lot of further digging and testing, and I think the issue is that the insert into the first table isn’t sending the LpcMemberID in the post message since that field is an auto-increment field, and my understanding of the function gets its data from either the $_GET or $_POST data. Looking at the debug log I never see any value set for $cid other than _empty, so the setAfterCrudAction sql fails with an error (I had to enable error logs in my DB engine).

    So the question is – is it even possible to get the last primary key value (LpcMemberID) in the script?

    in reply to: Grid Update Uses rowID instead of Primary Key #128094
    kgrogers
    Participant

    Will:

    Good grief, all that because I forgot to capitalize an ‘m’!

    All I had to do was correct the select statement for the proper case.

    Thank you for your quick reply.

     

    Ken

    in reply to: Set rowHeight with wrap #128046
    kgrogers
    Participant

    What is the secret to formatting code like you did in your post above? I did it once years ago and now can’t for the life of me figure out how to do it.

     

    Can you post a sticky post somewhere with instructions on how to post things like that in this forum?

    • This reply was modified 7 months, 2 weeks ago by kgrogers.
    • This reply was modified 7 months, 2 weeks ago by kgrogers.
    in reply to: Set rowHeight with wrap #128045
    kgrogers
    Participant

    Hi Will:

     

    I implemented the changes but I am getting an error.  Here is my index.php file:

    In my grid.php file I added the following:

    The error is reported in the developer console:

    Ken

    • This reply was modified 7 months, 2 weeks ago by kgrogers.
    • This reply was modified 7 months, 2 weeks ago by kgrogers.
Viewing 15 replies - 1 through 15 (of 35 total)

Stay connected with us in your favorite flavor!