Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted on Nov 30, 2009 05:39
open dhtmlx forum
problem of fetching data using php using dhtmlx

I am using this code

<div id="products_grid" style="width:500px;height:200px;">ff</div>

<script>

     var mygrid = new dhtmlXGridObject('products_grid');

mygrid.setImagePath("codebase/images/");

         mygrid.enableSmartRendering(true,50);

mygrid.setHeader("Product Name,Internal Code,Price");

mygrid.setInitWidths("*,150,150");

mygrid.setColAlign("left,left,right");

        mygrid.setSkin("modern");

        mygrid.setColSorting("server,server,server");

        mygrid.init();

        mygrid.enableSmartRendering(true);

        gridQString = "getGridRecords.php";

        mygrid.loadXML(gridQString);

        mygrid.attachEvent("onBeforeSorting",sortGridOnServer)



</script>




    <link rel="STYLESHEET" type="text/css" href="../codebase/dhtmlxgrid.css">

    <link rel="STYLESHEET" type="text/css" href="../common/styles.css">

    <script src="../codebase/dhtmlxcommon.js"></script>

    <script src="../codebase/dhtmlxgrid.js"></script>



    <script src="../codebase/dhtmlxgridcell.js"></script>




this is my php file <?php

//set content type and xml tag

header("Content-type:text/xml");

print("<?xml version=\"1.0\"?>");



//define variables from incoming values

if(isset($_GET["posStart"]))

$posStart = $_GET['posStart'];

else

$posStart = 0;

if(isset($_GET["count"]))

$count = $_GET['count'];

else

$count = 100;



//connect to database

$link = mysql_pconnect("localhost", "root", "");

$db = mysql_select_db ("sampleDB");



//query to products table

$sql = "SELECT * FROM products";

    if(isset($_GET["name_mask"]))

        $sql.=" Where nm like '".$_GET["name_mask"]."%'";



//if this is first query - get total number of records in query result

if($posStart==0){

$sqlCount = "Select count(*) as cnt from ($sql) as tbl";

$resCount = mysql_query ($sqlCount);

$rowCount=mysql_fetch_array($resCount);

$totalCount = $rowCount["cnt"];

}

    //order by

    $columns = array("nm","code","num_val");

    if(isset($_GET["orderby"])){

        if($_GET["direct"]=='des')

            $direct = "DESC";

        else    

            $direct = "ASC";

        $sql.=" Order by ".$columns[$_GET["orderby"]]." ".$direct;

    }

    

//add limits to query to get only rows necessary for output

$sql.= " LIMIT ".$posStart.",".$count;

    

        

    $res = mysql_query ($sql);

//output data in XML format

print("<rows total_count='".$totalCount."' pos='".$posStart."'>");

while($row=mysql_fetch_array($res)){

print("<row id='".$row['id']."'>");

print("<cell>");

print($row['nm']); //value for product name

print("</cell>");

print("<cell>");

print($row['code']); //value for internal code

print("</cell>");

print("<cell>");

print($row['num_val']); //value for price

print("</cell>");

print("</row>");

}

print("</rows>");

?>



please tell me solutions
Answer posted by dhxSupport on Nov 30, 2009 07:46
Your code seems correct. To simplify server side operations related DHTMLX component you try to use dhtmlxConnectors. Please find more information here http://dhtmlx.com/docs/products/dhtmlxConnector/index.shtml and tutorial here http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxconnector:toc