<html>
<head>
<title>PHP table</title>
<style> body, html {margin:0px; padding: 0px; overflow: hidden;} </style>
<!-- ActiveWidgets stylesheet and scripts -->
<link href="..runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="../runtime/lib/grid.js"></script>
<!-- ActiveWidgets PHP functions -->
<?php include("activewidgets.php") ?>
<!-- grid format -->
<style>
.active-templates-input {
overflow: hidden;
width: 100%;
height: 100%;
padding: 0px 5px;
margin: -1px 0px;
border: 1px solid #666;
vertical-align: middle;
font: menu;
line-height: 1.4em;
}
.active-templates-input.gecko {
display: block;
margin: 0px;
}
</style>
<!-- grid data -->
<script>
if (!window.My) My=[];
if (!My.Templates) My.Templates=[];
My.Templates.Input = Active.Templates.Text.subclass();
My.Templates.Input.create = function()
{
var obj = this.prototype;
// editor is not part of the template,
// there is only one single instance of editor object.
var editor = new Active.HTML.INPUT;
editor.setClass("templates", "input");
editor.setAttribute("type", "text");
editor.setAttribute("value", function(){
return template.getItemProperty("text");
});
// template variable provides temporary reference
// to the parent template during edit mode.
var template;
function switchToEditMode(){
if (template) {
switchToTextMode()
}
template = this;
template.element().style.padding = 0;
template.element().innerHTML = editor;
editor.element().focus();
}
obj.setEvent("ondblclick", switchToEditMode);
function switchToTextMode(){
var value = editor.element().value;
template.setItemProperty("text", value);
template.refresh();
template = null;
}
editor.setEvent("onblur", switchToTextMode);
};
My.Templates.Input.create();
var myData = new Array();
<?
$link = mysql_connect("127.0.0.1", "****", "******");
// echo "Connection made";
mysql_select_db("test");
register_shutdown_function($close);
$sql = "Select `Hostname` , `Spec` , `Booked_By` , `Project` , `Subproject` ,`Proj_Mgr`, `Dept_Mgr`, `Purpose`, `Comments`, `TestSite_Type` from `tp`";
$result = mysql_query($sql , $link);
while ( $row = mysql_fetch_array($result))
{
echo 'myData.push["'.$row['Hostname']
.'","'.$row['Spec']
.'","'.$row['Booked_By']
.'","'.$row['Project']
.'","'.$row['Subproject']
.'","'.$row['Proj_Mgr']
.'","'.$row['Dept_Mgr']
.'","'.$row['Purpose']
.'","'.$row['Comments']
.'","'.$row['TestSite_Type'].'"'
.']';
}
?>
var myColumns = [ "Hostname", "Spec", "Booked_By", "Project", "Subproject" , "Proj_Mgr" , "Dept_Mgr" , "Purpose" ,"Comms" , "TestSite_Type" ];
</script>
</head>
<body>
<script>
// create ActiveWidgets Grid javascript object
var obj = new Active.Controls.Grid;
// set number of rows/columns
obj.setRowCount(20);
obj.setColumnCount(5);
// provide cells and headers text
// create editable text template
var templ = new My.Templates.Input;
// assign new template to all columns
obj.setColumnTemplate(templ);
// provide methods for getting and setting data
obj.getDataText = function(i, j){return myData[i][j]};
obj.setDataText = function(value, i, j){myData[i][j] = value};
obj.setColumnText(function(i){return myColumns[i]});
// disable arrow key nevigation
obj.setEvent("onkeydown", null);
// make input box selectable
obj.getTemplate("top").setEvent("onselectstart", obj.getEvent("onselectstart"));
obj.setEvent("onselectstart", null);
// set click action handler
//obj.setAction("click", function(src){window.status = src.getProperty("item/text")});
// write grid html to the page
document.write(obj);
</script>
</body>
</html>
var myColumns = [ "Hostname", "Sp..............
</script>
<?
$link = mysql_connect("127.0.0.1", "****", .................
<html>
<head>
<title>Hardware Requests :: PHP Example</title>
<style> body, html {margin:0px; padding: 0px; overflow: hidden;} </style>
<!-- ActiveWidgets stylesheet and scripts -->
<link href="..runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="../runtime/lib/grid.js"></script>
<!-- ActiveWidgets PHP functions -->
<?php include("activewidgets.php") ?>
<!-- grid format -->
<style>
.active-templates-input {
overflow: hidden;
width: 100%;
height: 100%;
padding: 0px 5px;
margin: -1px 0px;
border: 1px solid #666;
vertical-align: middle;
font: menu;
line-height: 1.4em;
}
.active-templates-input.gecko {
display: block;
margin: 0px;
}
</style>
<!-- grid data -->
<script>
if (!window.My) My=[];
if (!My.Templates) My.Templates=[];
My.Templates.Input = Active.Templates.Text.subclass();
My.Templates.Input.create = function()
{
var obj = this.prototype;
// editor is not part of the template,
// there is only one single instance of editor object.
var editor = new Active.HTML.INPUT;
editor.setClass("templates", "input");
editor.setAttribute("type", "text");
editor.setAttribute("value", function(){
return template.getItemProperty("text");
});
// template variable provides temporary reference
// to the parent template during edit mode.
var template;
function switchToEditMode(){
if (template) {
switchToTextMode()
}
template = this;
template.element().style.padding = 0;
template.element().innerHTML = editor;
editor.element().focus();
}
obj.setEvent("ondblclick", switchToEditMode);
function switchToTextMode(){
var value = editor.element().value;
template.setItemProperty("text", value);
template.refresh();
template = null;
}
editor.setEvent("onblur", switchToTextMode);
};
My.Templates.Input.create();
var myData = new Array();
<?
// grid object name
$name = "obj";
// SQL query
$query = "select * from `tp` limit 0,20";
// database connection
$connection = mysql_connect("local", "$name", "$pass");
mysql_select_db("test");
// query results
$data = mysql_query($query, $connection);
// add grid to the page
// echo activewidgets_grid($name, $data);
while ( $row = mysql_fetch_array($data))
{
echo 'myData.push["'.$row['Hostname']
.'","'.$row['Spec']
.'","'.$row['Booked_By']
.'","'.$row['Project']
.'","'.$row['Subproject']
.'","'.$row['Proj_Mgr']
.'","'.$row['Dept_Mgr']
.'","'.$row['Purpose']
.'","'.$row['Comments']
.'","'.$row['TestSite_Type'].'"'
.']';
}
?>
var myColumns = [ "Hostname", "Spec", "Booked_By", "Project", "Subproject" , "Proj_Mgr" , "Dept_Mgr" , "Purpose" ,"Comms" , "TestSite_Type" ];
</script>
</head>
<body>
<script>
// create ActiveWidgets Grid javascript object
var obj = new Active.Controls.Grid;
// set number of rows/columns
obj.setRowCount(20);
obj.setColumnCount(5);
// provide cells and headers text
// create editable text template
var templ = new My.Templates.Input;
// assign new template to all columns
obj.setColumnTemplate(templ);
// provide methods for getting and setting data
obj.getDataText = function(i, j){return myData[i][j]};
obj.setDataText = function(value, i, j){myData[i][j] = value};
obj.setColumnText(function(i){return myColumns[i]});
// disable arrow key nevigation
obj.setEvent("onkeydown", null);
// make input box selectable
obj.getTemplate("top").setEvent("onselectstart", obj.getEvent("onselectstart"));
obj.setEvent("onselectstart", null);
// set click action handler
obj.setAction("click", function(src){window.status = src.getProperty("item/text")});
// write grid html to the page
document.write(obj);
</script>
</body>
</html>
<html>
<head>
<title>Hardware Requests :: PHP Example</title>
<style> body, html {margin:0px; padding: 0px; overflow: hidden;} </style>
<!-- ActiveWidgets stylesheet and scripts -->
<link href="..runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="../runtime/lib/grid.js"></script>
<!-- ActiveWidgets PHP functions -->
<?php include("activewidgets.php") ?>
<!-- grid format -->
<style>
.active-templates-input {
overflow: hidden;
width: 100%;
height: 100%;
padding: 0px 5px;
margin: -1px 0px;
border: 1px solid #666;
vertical-align: middle;
font: menu;
line-height: 1.4em;
}
.active-templates-input.gecko {
display: block;
margin: 0px;
}
</style>
<!-- grid data -->
<script>
if (!window.My) My=[];
if (!My.Templates) My.Templates=[];
My.Templates.Input = Active.Templates.Text.subclass();
My.Templates.Input.create = function()
{
var obj = this.prototype;
// editor is not part of the template,
// there is only one single instance of editor object.
var editor = new Active.HTML.INPUT;
editor.setClass("templates", "input");
editor.setAttribute("type", "text");
editor.setAttribute("value", function(){
return template.getItemProperty("text");
});
// template variable provides temporary reference
// to the parent template during edit mode.
var template;
function switchToEditMode(){
if (template) {
switchToTextMode()
}
template = this;
template.element().style.padding = 0;
template.element().innerHTML = editor;
editor.element().focus();
}
obj.setEvent("ondblclick", switchToEditMode);
function switchToTextMode(){
var value = editor.element().value;
template.setItemProperty("text", value);
template.refresh();
template = null;
}
editor.setEvent("onblur", switchToTextMode);
};
My.Templates.Input.create();
var myData = new Array();
var myColumns = [ "Hostname", "Spec", "Booked_By", "Project", "Subproject" , "Proj_Mgr" , "Dept_Mgr" , "Purpose" ,"Comms" , "TestSite_Type" ];
</script>
<?
// grid object name
$name = "obj";
// SQL query
$query = "select * from `tp` limit 0,20";
// database connection
$connection = mysql_connect("127.0.0.1", "root", "123456");
mysql_select_db("test");
// query results
$data = mysql_query($query, $connection);
// add grid to the page
// echo activewidgets_grid($name, $data);
while ( $row = mysql_fetch_array($data))
{
echo 'myData.push["'.$row['Hostname']
.'","'.$row['Spec']
.'","'.$row['Booked_By']
.'","'.$row['Project']
.'","'.$row['Subproject']
.'","'.$row['Proj_Mgr']
.'","'.$row['Dept_Mgr']
.'","'.$row['Purpose']
.'","'.$row['Comments']
.'","'.$row['TestSite_Type'].'"'
.']';
}
?>
</head>
<body>
<script>
// create ActiveWidgets Grid javascript object
var obj = new Active.Controls.Grid;
// set number of rows/columns
obj.setRowCount(20);
obj.setColumnCount(5);
// provide cells and headers text
// create editable text template
var templ = new My.Templates.Input;
// assign new template to all columns
obj.setColumnTemplate(templ);
// provide methods for getting and setting data
obj.getDataText = function(i, j){return myData[i][j]};
obj.setDataText = function(value, i, j){myData[i][j] = value};
obj.setColumnText(function(i){return myColumns[i]});
// disable arrow key nevigation
obj.setEvent("onkeydown", null);
// make input box selectable
obj.getTemplate("top").setEvent("onselectstart", obj.getEvent("onselectstart"));
obj.setEvent("onselectstart", null);
// set click action handler
obj.setAction("click", function(src){window.status = src.getProperty("item/text")});
// write grid html to the page
document.write(obj);
</script>
</body>
</html>
<link href="..runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="../runtime/lib/grid.js"></script>
while ( $row = mysql_fetch_array($data))
{
echo 'myData.push["'.$row['Hostname']
.'","'.$row['Spec']
.'","'.$row['Booked_By']
.'","'.$row['Project']
.'","'.$row['Subproject']
.'","'.$row['Proj_Mgr']
.'","'.$row['Dept_Mgr']
.'","'.$row['Purpose']
.'","'.$row['Comments']
.'","'.$row['TestSite_Type'].'"'
.']';
}
$columns .= ($i>0 ? ",\"":"\"");
$columns .= $tempdb->sql_fieldname($i,$tempres)."\"";
}
$columns .= "\n];\n";
$rows = "var myData = [\n"; //START myData ARRAY CONTENT
//sql_fetchrow is similar to while($row = mysql_fetch_array($data)) { ..do something }
//but i used the for loop
for ($i=0; $i <= $row_count-1; $i++) {
$datarow = $tempdb->sql_fetchrow($tempres);// similar to mysql_fetch_row
// this will prevent your array to look like this myData=[,["val1","val2","val3"],["val1","val2","val3"]];
$rows .= ($i>0 ? ",[":"[");
for ($j=0; $j <= $column_count-1; $j++) {
$rows .= ($j>0 ? ",":" ");
$rows .= "\"".Nil(Modify_html($datarow[$j]),'-')."\" ";
}
$rows .= "]\n";
}
$rows .= "];\n"; //END myData ARRAY CONTENT
// format javascript to ouput
$htmlstr = "<"."script".">\n";
$htmlstr .= $columns;
$htmlstr .= "\n";
$htmlstr .= $rows;
$htmlstr .= "</"."script".">\n";
// output your javascript
echo $htmlstr;
/********************************
// functions
/********************************/
function Modify_html($msg){
$msg = addslashes($msg);
$msg = str_replace("\n", "\\n", $msg);
$msg = str_replace("\r", "\\r", $msg);
$msg = htmlspecialchars($msg);
return $msg;
}
$name = "obj";
// SQL query
$query = "select * from `tp` limit 0,20";
// database connection
$connection = mysql_connect("local", "$name", "$pass");
mysql_select_db("test");
// query results
$data = mysql_query($query, $connection);
$columns .= $tempdb->sql_fieldname($i,$tempres)."\"";
$columns .= $tempdb->sql_fieldname($i,$data)."\"";
echo 'var myData = new Array();'; // New line added
while ( $row = mysql_fetch_array($data))
{
echo 'myData.push["'.$row['Hostname']
.'","'.$row['Spec']
.'","'.$row['Booked_By']
.'","'.$row['Project']
.'","'.$row['Subproject']
.'","'.$row['Proj_Mgr']
.'","'.$row['Dept_Mgr']
.'","'.$row['Purpose']
.'","'.$row['Comments']
.'","'.$row['TestSite_Type'].'"'
.'];'; // this line was changed
}
<?php
/********************************************************************
* filename: mysql.php
********************************************************************/
class sql_db
{
var $db_connect_id;
var $query_result;
var $row = array();
var $rowset = array();
var $num_queries = 0;
//
// Constructor
//
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->persistency = $persistency;
$this->user = $sqluser;
$this->password = $sqlpassword;
$this->server = $sqlserver;
$this->dbname = $database;
if($this->persistency)
{
$this->db_connect_id = @mysql_pconnect($this->server, $this->user, $this->password);
}
else
{
$this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password);
}
if($this->db_connect_id)
{
if($database != "")
{
$this->dbname = $database;
$dbselect = @mysql_select_db($this->dbname);
if(!$dbselect)
{
@mysql_close($this->db_connect_id);
$this->db_connect_id = $dbselect;
}
}
return $this->db_connect_id;
}
else
{
return false;
}
}
//
// Other base methods
//
function sql_close()
{
if($this->db_connect_id)
{
if($this->query_result)
{
@mysql_free_result($this->query_result);
}
$result = @mysql_close($this->db_connect_id);
return $result;
}
else
{
return false;
}
}
//
// Base query method
//
function sql_query($query = "", $transaction = FALSE)
{
// Remove any pre-existing queries
unset($this->query_result);
if($query != "")
{
$this->num_queries++;
$this->query_result = @mysql_query($query, $this->db_connect_id);
}
if($this->query_result)
{
unset($this->row[$this->query_result]);
unset($this->rowset[$this->query_result]);
return $this->query_result;
}
else
{
return ( $transaction == END_TRANSACTION ) ? true : false;
}
}
//
// Other query methods
//
function sql_numrows($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @mysql_num_rows($query_id);
return $result;
}
else
{
return false;
}
}
function sql_affectedrows()
{
if($this->db_connect_id)
{
$result = @mysql_affected_rows($this->db_connect_id);
return $result;
}
else
{
return false;
}
}
function sql_numfields($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @mysql_num_fields($query_id);
return $result;
}
else
{
return false;
}
}
function sql_fieldname($offset, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @mysql_field_name($query_id, $offset);
return $result;
}
else
{
return false;
}
}
function sql_fieldtype($offset, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @mysql_field_type($query_id, $offset);
return $result;
}
else
{
return false;
}
}
function sql_fetchrow($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$this->row[$query_id] = @mysql_fetch_array($query_id);
return $this->row[$query_id];
}
else
{
return false;
}
}
function sql_fetchrowset($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
unset($this->rowset[$query_id]);
unset($this->row[$query_id]);
while($this->rowset[$query_id] = @mysql_fetch_array($query_id))
{
$result[] = $this->rowset[$query_id];
}
return $result;
}
else
{
return false;
}
}
function sql_fetchfield($field, $rownum = -1, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
if($rownum > -1)
{
$result = @mysql_result($query_id, $rownum, $field);
}
else
{
if(empty($this->row[$query_id]) && empty($this->rowset[$query_id]))
{
if($this->sql_fetchrow())
{
$result = $this->row[$query_id][$field];
}
}
else
{
if($this->rowset[$query_id])
{
$result = $this->rowset[$query_id][$field];
}
else if($this->row[$query_id])
{
$result = $this->row[$query_id][$field];
}
}
}
return $result;
}
else
{
return false;
}
}
function sql_rowseek($rownum, $query_id = 0){
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @mysql_data_seek($query_id, $rownum);
return $result;
}
else
{
return false;
}
}
function sql_nextid(){
if($this->db_connect_id)
{
$result = @mysql_insert_id($this->db_connect_id);
return $result;
}
else
{
return false;
}
}
function sql_freeresult($query_id = 0){
if(!$query_id)
{
$query_id = $this->query_result;
}
if ( $query_id )
{
unset($this->row[$query_id]);
unset($this->rowset[$query_id]);
@mysql_free_result($query_id);
return true;
}
else
{
return false;
}
}
function sql_error($query_id = 0)
{
$result["message"] = @mysql_error($this->db_connect_id);
$result["code"] = @mysql_errno($this->db_connect_id);
return $result;
}
} // end of class sql_db
?>
<?php
//the grid page
require_once('mysql.php');
$tempdb=NULL;
$tempdb=new sql_db($db_host, $username, $passwd, $dbname, false);
if(!$tempdb->db_connect_id){
print "i cant connect to mysql database";
exit();
}
$strSQL="Select * from tblname";
$tempres=$tempdb->sql_query($strSQL);
if (!$tempres){
print "error in $strSQL";
exit();
}else{
$column_count = $tempdb->sql_numfields($tempres);
$row_count = $tempdb->sql_numrows($tempres);
$columns = "var myColumns= [\n";
for ($i=0; $i <= $column_count-1; $i++) {
$columns .= ($i>0 ? ",\"":"\"");
$columns .= $tempdb->sql_fieldname($i,$tempres)."\"";
}
$columns .= "\n];\n";
//**********************
// copy the eariler code i posted
//***********************
}
//end of php
?>
now create the grid and set its data
<!-------- AWGrid code-------->
<script>
// create ActiveWidgets Grid javascript object
var obj = new Active.Controls.Grid;
// set number of rows/columns
obj.setRowProperty("count", gridHeader_data.length);
obj.setColumnProperty("count", gridHeader_columns.length);
// provide cells and headers text
obj.setDataProperty("text", function(i, j){return gridHeader_data[i][j]});
obj.setColumnProperty("text", function(i){return gridHeader_columns[i]});
document.write(obj);
</script>
// set number of rows/columns
obj.setRowProperty("count", myData.length);
obj.setColumnProperty("count", myColumns.length);
$rows .= "\"".Nil(Modify_html($datarow[$j]),'-')."\" ";
function Modify_html($msg){
$msg = addslashes($msg);
$msg = str_replace("\n", "\\n", $msg);
$msg = str_replace("\r", "\\r", $msg);
$msg = htmlspecialchars($msg);
return $msg;
$rows .= "\"".Nil(Modify_html($datarow[$j]),'-')."\" ";
$rows .= "\"".Modify_html($datarow[$j])."\" ";
<?
//***************** stdfunctions.php**************
function IsNullOrEmpty($var){
if (is_null($var)){
return true;
}else{
return empty($var) ? true : false;
}
}
function Nil($varRef, $varReplace){
if (IsNullOrEmpty($varRef)){
return $varReplace;
}else{
if (is_string($varRef)){
if ($varRef==""){
return $varReplace;
}else{
return $varRef;
}
}else{
return $varRef;
}
}
}
// insert the modify function here
function IsNullOrEmpty($var){
if (is_null($var)){
return true;
}else{
return empty($var) ? true : false;
}
}
function Nil($varRef, $varReplace){
if (IsNullOrEmpty($varRef)){
return $varReplace;
}else{
if (is_string($varRef)){
if ($varRef==""){
return $varReplace;
}else{
return $varRef;
}
}else{
return $varRef;
}
}
}
?>
<?php
//the grid page
require_once('mysql.php');
// insert this code
require_once("stdfunction.php");
var obj = new Active.Controls.Grid;
// set number of rows/columns
obj.setRowProperty("count", myData.length);
obj.setColumnProperty("count", myColumns.length);
// provide cells and headers text
obj.getDataText = function(i, j){return myData[i][j]};
obj.setDataText = function(value, i, j){myData[i][j] = value};
obj.setColumnText(function(i){return myColumns[i]});
document.write(obj);
var myData = [["data","data","data"], ["data","data","data"]]
This topic is archived.