Hi guys...
i want to delete data from datagrid in mysql...i have also done update query using same datagrid...
but i m not able to delete data...
my code is

<script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var data = {};
            var theme = 'classic';

            var source =
            {
                 datatype: "json",
                 datafields: [
                     { name: 'name'},
                     { name: 'id'}
                ],
                id: 'id',
                url: 'data_qualification.php',          
                updaterow: function (rowid, rowdata, commit) {
                    // synchronize with the server - send update command
                    var data = "update=true&name=" + rowdata.name;
                    data = data + "&id=" + rowdata.id;

                    $.ajax({
                        dataType: 'json',
                        url: 'data_qualification.php',
                        data: data,
                        success: function (data, status, xhr) {
                            // update command is executed.
                            commit(true);
                        },



                ////I think here is some problem
                        deleterow: function (rowid, commit) {


                     var data = "delete=true&id=" + rowdata.id;
                    $.ajax({
                        dataType: 'json',
                        url: 'data_qualification.php',
                        data: data,
                        success: function (data, status, xhr) {

                            commit(true);
                        }
                    })}

                    });     
                }
            };













            var dataAdapter = new $.jqx.dataAdapter(source);

            // initialize jqxGrid
            $("#jqxgrid").jqxGrid(
            {
                width: 280,
                height: 350,
                selectionmode: 'singlecell',
                source: dataAdapter,
                theme: theme,
                editable: true,
                columns: [
                      { text: 'ID', editable: false, datafield: 'id', width: 100 },

                      { text: ' Certificate Name', datafield: 'name', width: 180 }

                  ]
            });
        });


        // delete row.
            $("#deleterowbutton").bind('click', function () {
                var selectedrowindex = $("#jqxgrid").jqxGrid('getselectedrowindex');
                var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;
                if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
                    var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex);
                    var commit = $("#jqxgrid").jqxGrid('deleterow', id);
                }
            });


    </script>

and my php code is

<?php
#Include the connect.php file
include('../Scripts/connection.php');
#Connect to the database
//connection String
$connect = mysql_connect($hostname, $username, $password)
or die('Could not connect: ' . mysql_error());
//Select The database
$bool = mysql_select_db($database, $connect);
if ($bool === False){
   print "can't find $database";
}
// get data and store in a json array
$query = "SELECT * FROM tblcertificate";

if (isset($_GET['update']))
{
    // UPDATE COMMAND 
    //$update_query = "UPDATE `tblcertificate` SET `name`='".mysql_real_escape_string($_GET['name'])."' WHERE `id`='".mysql_real_escape_string($_GET['id'])."'";

    $update_query = "update tblcertificate set name = '".mysql_real_escape_string($_GET['name'])."' where id = '".mysql_real_escape_string($_GET['id'])."' ";

     $result = mysql_query($update_query) or die("SQL Error 1: " . mysql_error());
     echo $result;
}


if (isset($_GET['delete']))
{
    // delete COMMAND 
    //$update_query = "UPDATE `tblcertificate` SET `name`='".mysql_real_escape_string($_GET['name'])."' WHERE `id`='".mysql_real_escape_string($_GET['id'])."'";

    $delete_query = "delete from tblcertificate  where id = '".mysql_real_escape_string($_GET['id'])."' ";

     $result = mysql_query($delete_query) or die("SQL Error 1: " . mysql_error());
     echo $result;
}




else
{
    // SELECT COMMAND
    $result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $certificate[] = array(
            'name' => $row['name'],
            'id' => $row['id']

          );
    }

    echo json_encode($certificate);
}
?>

Hoping for solution

Regards..
Farhad Idrees

i think you have to refresh your data grid after the delete operation
but i think you haven't done like that (as of my knowledge)
check it once and let me know the status

Where is the problem coming from? is it from the backend side or the js side?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.