<?php
require_once("codebase/connector/grid_connector.php");//includes connector file
$res=mysql_connect("localhost","user","password");//connects to server with db
mysql_select_db("sampledb");//connects to the database with the name "sampledb"
$conn = new GridConnector($res); //initializes the connector object
$conn->render_table("books","id","title,quantity,price"); //loads data from db
and for the html part:
<html>
<head>
<title>dhtmlxGrid. Server side</title>
<link rel="STYLESHEET" type="text/css" href="codebase/dhtmlxgrid.css">
<script src="codebase/dhtmlxgrid.js"></script>
</head>
<body>
<div id="mygrid_container" style="width:600px; height:160px;"></div>
<script>
dhtmlxEvent(window,"load",function(){
mygrid = new dhtmlXGridObject("mygrid_container");
mygrid.setImagePath("codebase/imgs/"); //sets the path to the source images
mygrid.setHeader("Name,Quantity,Price"); //sets the header labels
mygrid.setInitWidths("*,150,150"); //sets the initial widths of columns
mygrid.setColAlign("left,right,right"); //sets the horizontal alignment
mygrid.setColTypes("ed,ed,price"); //sets the types of columns
mygrid.setSkin("dhx_skyblue"); //sets the skin to apply
mygrid.init();
contactsGrid.load("data.php");
});
</script>
</body>
</html>
If you are using the old version of the dhtmlxgrid (i mean not a 4.x) you also need to include the connector.js library.
Please, make sure that you have configured the access to your database correctly:
$res=mysql_connect(“localhost”,“user”,“password”);//connects to server with db
check the login and password on your server
Please, make sure that you’ve created the required database table in your database:
mysql_select_db(“sampledb”);//connects to the database with the name “sampledb”
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan