Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by mahesh on Oct 31, 2009 11:35
open dhtmlx forum
dhtmlx grid and mySQL connection & XML load error with incorrect XML

I have struggled with this for a while and seem to have a problem I cannot solve. I tried using the documentation for setting up mySQL with the gridbox. I also tried the dhtmlxcommon_debug javascript which did not seem to help much. My code that I tried is below with some original sections commented out. Thanks,


******************<---PHONE.HTML CODE BELOW, means of entry-->


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>Radiologist phone list</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta name="featured" content="yes"><meta name="title" content="Phone list" />
         </div>
<link rel="STYLESHEET" type="text/css" href="codebase/dhtmlxgrid.css">
    <link rel="stylesheet" type="text/css" href="codebase/skins/dhtmlxgrid_dhx_skyblue.css">

    <script src="codebase/dhtmlxcommon.js"></script>
    <script src="codebase/dhtmlxgrid.js"></script>
<script src="codebase/ext/dhtmlxgrid_srnd.js"></script>
<script src="codebase/ext/dhtmlxgrid_filter.js"></script>        
    <script src="codebase/dhtmlxgridcell.js"></script>
    <script src="dhtmlxDataProcessor/codebase/dhtmlxdataprocessor.js"></script>



    <div id="gridbox" style="width:800px;height:600px;overflow:hidden"></div>
            
                
                <p><a href="javascript:void(0)" onclick="mygrid.addRow((new Date()).valueOf(),[0,'','','',false,'na',false,''],mygrid.getRowIndex(mygrid.getSelectedId()))">Add row</a></p>
                <p><a href="javascript:void(0)" onclick="mygrid.deleteSelectedItem()">Remove Selected Row</a></p>






<script>
    //init grid and set its parameters (this part as always)

    mygrid = new dhtmlXGridObject('gridbox');
    mygrid.setImagePath("codebase/imgs/");
    mygrid.setHeader(" Attendings,Phone, Residents,Phone, Reading Rooms,Phone, Pager numbers,Phone");
mygrid.attachHeader("#text_filter,#cspan,#text_filter,#cspan,#text_filter,#cspan,#text_filter,#cspan");
    mygrid.setInitWidths("120,50,120,50,120,50,120,50")
    mygrid.setColAlign("right,center,right,center,right,center,right,center")
    mygrid.setColTypes("txt,txt,txt,txt,txt,txt,txt,txt");
    mygrid.setSkin("dhx_skyblue");
mygrid.enableAutoWidth(true);
mygrid.enableSmartRendering(true);
    mygrid.setColSorting("str,str,str,str,str,str,str,str")
    mygrid.init();
    mygrid.load("php/get.php");
//mygrid.loadXML("100.xml");    //used just for demo purposes

    

    myDataProcessor = new dataProcessor("php/get.php"); //lock feed url
    myDataProcessor.init(mygrid); //link dataprocessor to the grid

</script>

    

<-**************get.php below***************>    
<?php

//include db connection settings
//change this setting according to your environment
require_once('config.php');
require_once('config_dp.php');
require("grid_connector.php");

$res=mysql_connect($mysql_server,$mysql_user,$mysql_pass);
    mysql_select_db($mysql_db);


//include XML Header (as response will be in xml format)
//header("Content-type: text/xml");
//encoding may be different in your case
//echo('<?xml version="1.0" encoding="iso-8859-1"?>');

//output data from DB as XML
//$sql = "SELECT * from samples_grid";
//$res = mysql_query ($sql);
//mysql_select_db($mysql_db);

$gridConn = new GridConnector($res,"MySQL");
$gridConn->render_table("attendings","phone","residents","phone2","reading rooms","phone3","pager numbers","phone4");

        
/*if($res){
    while($row=mysql_fetch_array($res)){
        //create xml tag for grid's row
        echo ("<row id='".$row['book_id']."'>");
        print("<cell><![CDATA[".$row['attendings']."]]></cell>");
        print("<cell><![CDATA[".$row['phone']."]]></cell>");
        print("<cell><![CDATA[".$row['residents']."]]></cell>");
        print("<cell><![CDATA[".$row['phone2']."]]></cell>");
        print("<cell><![CDATA[".$row['reading rooms']."]]></cell>");
        print("<cell><![CDATA[".$row['phone3']."]]></cell>");
        print("<cell><![CDATA[".$row['pager numbers']."]]></cell>");
print("<cell><![CDATA[".$row['phone4']."]]></cell>");
        print("<cell><![CDATA[".gmdate("m/d/Y",strtotime($row['pub_date']))."]]></cell>");
        print("</row>");
    }
}else{
//error occurs
    echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
}

echo '</rows>';
*/

?>
Answer posted by dhxSupport on Nov 02, 2009 03:18
To use connectors you should attach connector.js file to your page. Also you can switch logging on the server side to check what error occurs while loading data in grid:
$gridConn->enable_log("temp.log",true);