3.2.0

Does grid template support mysql?

I want to use the aw grid to display and edit data but i cant get it to work. Does aw template mysql
I have a deadline comin up and it wud be great if i could get this goin 2day

Here is my code:

<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>


I keep getting a " 'My' is undefined " error .
I so frustrated now i feel like packin in aw alltogether and using something else.

Thanks for help



VERY-UPSET-DUDE
August 24,
I think I catch it !!
end your <script> tags before php code <?
like:
var myColumns = [ "Hostname", "Sp..............
</script>                        
<? 
  $link = mysql_connect("127.0.0.1", "****", .................
August 24,
i had a few of my own errors in dat code sorry:

<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>
VERY-UPSET-DUDE
August 24,
like this ?:


<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>


i tried dat and got the following error:

"myData[] is null or not an object".

and on de page itself was all this stuff:


myData.push["atrcus141","SFV440","EEIJCON","Maintenance","RC2.1 Sybase","EEIBHK","EEIPSN","Maintneance","2 * 3310 arrays. 1 * 73GB internal","System "]myData.push["atrcus51","SFV240","EEIKLS","R2.2 Maintenance","WRAN CM","EEIKLS","EEIJME","Design/Test","","Feature "]myData.push["netsim16","U10","EEIKLS","","","EEIKLS","EEIJME","Design/Test","","Feature "]myData.push["netsim205","SFV100","EEIKLS","","","EEIKLS","EEIJME","Design/Test","","Feature "]myData.push["atrcus21","SFV240","EEIKLS","R2.2 Maintenance","WRAN CM","EEIKLS","EEIJME","Design/Test","","Feature "]myData.push["attembak","SFV440","EEIEOCR","Backup/Restore","Backup/Restore","EEIEOCR","EEIBBH","Backup/Restore","","System "]myData.push["netsim254","SFV100","EEIKLS","","","EEIKLS","EEIJME","Design/Test","","Feature "]myData.push["atrcus19","SFV240","EEIKLS","R2.2","WRAN CM","EEIKLS","EEIJME","Design/Test","","Feature "]myData.push["atrcus107","SE250","EDBEDSR","R2","Maintenance","EDBEDSR","EEIJME","WRAN Ex / WRAN FWK / CSW Troubleshooting","","Feature "]myData.push["atrcus167","SFV890","EEIDDUA","P2.1","Maintenance","EEIDDUA","EEIPSN","R2 PLM","","System "]myData.push["atrnus73","SF280R","EEIIKY","R3","WRAN CM","EEIPLN","EEIJME","FET","","Feature "]myData.push["atrcus109","SE420","EEIDRYAN","R2.1","WRANCM","EEIPLN","EEIJME","FET","","Wilma "]myData.push["atrcus160","SFV890","EEIJCON","R3","NPT","EEIJCON","EEIMMUY","Large Upgrade","2 * 3510","System "]myData.push["netsim245","SFV100","EEIJTAR","","","EEIJCON","EEIMMUY","Wilma","","Wilma "]myData.push["atrcus102","SE250","EDBEDSR","R2","Maintenance","EDBEDSR","EEIJME","PCA Troubleshooting","","Feature "]myData.push["atrcus162","SFV890","EEIJCON","R3","NPT","EEIJCON","EEIMMUY","DDS","","System "]myData.push["atrcus82","SFV240","EDBEDSR","R2","Maintenance","EDBEDSR","EEIJME","PCA Troubleshooting","","Feature "]myData.push["atrcus106","SE250","EEIBBRY","R3","Radio","EEIBBRY","EEIJME","Design test","","Feature "]myData.push["atrcus163","SFV890","EEIJCON","R3","NPT","EEIJCON","EEIMMUY","Small Upgrade","","System "]myData.push["atrcus75","SFV240","EEIDOSY","R3","RNH","EEIBBRY","EEIJME","BIT","","Feature "] undefined


plaese please help
VERY-UPSET-DUDE
August 24,
That's because css
Please revise your corrections !!
good luck

<link href="..runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>

INSTEAD OF

<link href="../runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
August 24,
ok i replaced it now and the "'My' is undefined error is back.


<link href="..runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
    <script src="../runtime/lib/grid.js"></script>



any ideas?
VERY-UPSET-DUDE
August 24,
Any one?
VERY-UPSET-DUDE
August 24,
I would start by removing the MySQL and put in a dummy associative array. simplify the code, test, then add.

I played with your code for about the last 30 min and came up with undefined with JUST the Active Widget code (everything else commented out).
Jack9
August 24,
thanks for your effort Jack9..

yes i tried it as u said there yesterday and it worked fine but when i want to add an sql db array i get dat stupid error that makes no sense..

" 'My' is undefined " error when clearly it is defined because it works with the dummy associative array.


I dono what to do anymore .is there another way of changing a mysql grid into an editable grid? if not will the new version support an mysql editable grid and when is it due out?

cheers.
VERY-UPSET-DUDE
August 24,
MySQL doesnt interact with AW in any way. PHP reders the HTML (including the values from any Database) before AW even gets ahold of it. So we can be very very sure your problems are not with MySQL.

By examining the sourcecode of the page generated by the dummy array and the sourcecode generated by the mysql generated array, you will be able to see the practical differences that are causing the problem.
Jack9
August 24,
ok im goin 2 try a few things i found out. il get back to ye.
VERY-UPSET-DUDE
August 24,
hey,

my advice to you, you should have look at AW grid html source code .
You will know how the myData and myColumns being presented in javascript... its..

<script>
myData=[
["item0","item1","item2"],
["item0","item1","item2"],
["item0","item1","item2"]
];
myColumns=["col0","col1","col2"];
</script>
by using mysql ang php you should have an output like this...
if you use myData.push... you should have enclosed it with
like this
<script>
myData.Push(["item0","item1","item2"]);
</script>

glennlosentes
August 24,
its the way you create the array from mysql.

remember, you're working with javascript here as well, so you CANNOT have something like this :

array[0][1] = "jou ma"array[0][2]="jou pa" like you did here :

myData.push["atrcus141","SFV440","EEIJCON","Maintenance","RC2.1 Sybase","EEIBHK","EEIPSN","Maintneance","2 * 3310 arrays. 1 * 73GB internal","System "]myData.push["atrcus51","SFV240","EEIKLS","R2.2 Maintenance","WRAN CM","EEIKLS","EEIJME","Design/Test","","Feature "]myData.push["netsim16","U10","EEIKLS","","","EEIKLS","EEIJME","Design/Test","","Feature "]myData.push

you need a carriage return after each line or else it will give you an error.

In vb it is &vbcrlf

How many years programming experience do you have btw?
AcidRaZor
August 25,
wat ye on about.. i dont have dat in my code.. dats what was printed out on the screen... iv done 3 yrs in java in collage and im only doin php/javascript/html a week.
VERY-UPSET-DUDE
August 25,
java and javascript is very similar. i wanted to assess your experience because to me it seems you're not able to debug rather simple problems.

i'd suggest trying to go back to square one and play around with a working grid. then under examples there is a XML request example (called yahoo something) and look at how that functions.

from there it should be easy to understand
AcidRaZor
August 25,
but why did ye give me this

myData.push["atrcus141","SFV440","EEIJCON","Maintenance","RC2.1 Sybase","EEIBHK","EEIPSN","Maintneance","2 * 3310 arrays. 1 * 73GB internal","System "]myData.push["atrcus51","SFV240","EEIKLS","R2.2 Maintenance","WRAN CM","EEIKLS","EEIJME","Design/Test","","Feature "]myData.push["netsim16","U10","EEIKLS","","","EEIKLS","EEIJME","Design/Test","","Feature "]myData.push


when its not even in my code.. r u tryin to explain to me that this is wrong:

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'].'"' 
.']'; 
}
VERY-UPSET-DUDE
August 25,
how is the xml example usefull to me when im using a mysql database?
VERY-UPSET-DUDE
August 25,
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'].'"'
.'])';

That is what people are saying you are outputting bad javascript
J
August 25,
sorry forgot the ;

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'].'"'
.']);';
J
August 25,
ok push doesnt work at all

but this works 4 1 line..

$row = mysql_fetch_array($data);

echo 'myData = [["'.$row['Hostname'].'","'.$row['Spec'].'","'.$row['Booked_By'].'","'.$row['Project'].'","'.$row['Subproject'].'","'.$row['Proj_Mgr'].'","'.$row['Dept_Mgr'].'","'.$row['Purpose'].'","'.$row['Comments'].'","'.ctype_xdigit($row['TestSite_Type']).'"]];'

now i need a while loop r sumthing to add all the query result to the array. like while($row = mysql_fetch_array($data))

does any1 have a quick solution to this cos i spent 4 days so far 2 get this much
VERY-UPSET-DUDE
August 25,
Yes, sorry I wasn't clear enough. The javascript output you did was bad.

Javascript is REALLY finicky about certain things. For instance :

myArray[0] = [1,2,3]
myArray[1] = [1,2,3]

would work, but

myArray[0] = [1,2,3]myArray[1] = [1,2,3]

would not.

The XML example is useful in the sense that you can execute a server side script (like ASP or PHP) and return a text array that will populate the grid. That way you don't have to physically code the array like you're trying to do, and just return a comma delimited (with a carriage feed return at the end of the row)

The grid will do the rest of the work.

hope im a bit more clear? english is not my first language
AcidRaZor
August 25,
i aggree its very hard 2 get it to work especially for alot of lines.

but if im updateing the table afterwords can i still use this method
VERY-UPSET-DUDE
August 25,
but for starters like and under pressure of project deadline
this will do...
$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;
}


*use your echo or print in such a way that it will output a good javascript syntax.
glennlosentes
August 25,
oh cheers glennlosentes. this looks very nice. a few questions if ur not 2 busy.

this is the mySql stuff :

$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);


so do i change dis line:

$columns .= $tempdb->sql_fieldname($i,$tempres)."\"";


to this


$columns .= $tempdb->sql_fieldname($i,$data)."\"";





sorry for asking stupid questions but im still learning.



VERY-UPSET-DUDE
August 25,
In my opinion, there were 2 things wrong with his original array creation. If he declared myData as an array and had a semi-colon after each push statement it should work. Change the code to look like this ans d give it a try.

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
}


In the future, when someone offers you assistance, don't bad mouth them. When you were shown the output of YOUR CODE and it was explained why it didn't work, DON'T GET DEFENSIVE and state "wat ye on about.. i dont have dat in my code.. dats what was printed out on the screen... iv done 3 yrs in java in collage and im only doin php/javascript/html a week.". The person was correct and YOUR CODE DID PRODUCE THE RESULT on the screen. And for a supposed college educated person, you are extremely rude, ignorant, and can't handle basic debugging. And I really don't know why I even helped you out here except that perhaps if you have a solution you will be quiet and start respecting others and this thread will close. Many people have spent a lot of time with this issue and you don't seem at all grateful.

Good day...
VERY-UPSET at VERY-UPSET-DUDE
August 25,
NO...
i made a class for mysql database routines and used that class
<?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


?>


save that as mysql.php
next...


<?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>


display the grid the way you want it
glennlosentes
August 25,
sorry about this ....
use this instead

//    set number of rows/columns 
    obj.setRowProperty("count", myData.length); 
    obj.setColumnProperty("count", myColumns.length);
glennlosentes
August 25,
sorry VERY-UPSET at VERY-UPSET-DUDE..the frustration got the better of me and i was getting very impatient. Im very sorry if i offended anyone else as well. Thanks for all the effort.
VERY-UPSET-DUDE
August 25,
glennlosentes ur an absolute legend. Thank you.
VERY-UPSET-DUDE
August 25,
hi glennlosentes

i tried that code you gave me this mornng.. it doesnt work. but i think i found the problem in this line:

$rows .= "\"".Nil(Modify_html($datarow[$j]),'-')."\" ";


Because i did an echo on $row all the way up to here and i dont think this line is not doin what its supposed to.



Am i settin it upright. Im not sure where to put this:
function Modify_html($msg){

    $msg = addslashes($msg);
    $msg = str_replace("\n", "\\n", $msg);
    $msg = str_replace("\r", "\\r", $msg);
    $msg = htmlspecialchars($msg);

    return $msg;


sorry for bothering you again.
VERY-UPSET-DUDE
August 26,
ya its defently this row

$rows .= "\"".Nil(Modify_html($datarow[$j]),'-')."\" ";


because i got a print out for row all the way up to this line
VERY-UPSET-DUDE
August 26,
i think your doin fine... sorry about the Nil.
Nil is also a function that i made...to replace NULL value with its second parameter. you may not use that...
$rows .= "\"".Modify_html($datarow[$j])."\" ";



Modify_html is a function so define that function you may define it in a separate page just like mysql.php and include the page if you want to use it...

include this for your use..
<? 
//***************** 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;
        }
    }
}
?>

save it as stdfunction.php
include it after including mysql.php
<?php 
//the grid page 
require_once('mysql.php'); 
// insert this code
require_once("stdfunction.php");


i hope this will help





glennlosentes
August 26,
sorry very upset guy... i pasted the code twice...
glennlosentes
August 26,
nerly workin now. for sum strange reason it is printing all the data out on creeen instead of putting it in to a table like it shud..


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);


iv changed dis around a bit still de same result
VERY-UPSET-DUDE
August 26,
it working!!!!!

i forgot my styles.. i cannot be more greatfull glennlosentes.. my deadline is today and i was really sweating it.. cheers..

not VERY-UPSET-DUDE anymore
August 26,
good to hear that... i hope some of the AW coders answers to topic i posted about the asyn fetch to the database...

til next time...
glennlosentes
August 26,
please i need the full sample, for update mysql table.


thanks,

zsamer
January 27,
yes, could be nice if someone can post the completed project for all.
noone ?
should be shared...
January 29,
Why not a HOW-TO from the developers? We really need this, many people is reinventing the wheel to fill a grid with mysql data and then edit it.

Please...
joakinen
February 28,
Everyone has to understand that the grid is a client-side control. The data can come from a thousand different places. It doesn't matter where it comes from as long as it's in the correct format. People creating web pages should be a little familiar with the databases they are interacting with. It's not up to the people who write the client side controls to teach you how to write server side code or how to interact with the hundreds of different databases mixed with the dozens of different scripting languages. That is the responsibility of the web page designer. In short, all of us. If you are having problems working with your database, I suggest going to the web site of the people that created it and asking them how to retrieve data from it using whatever server side scripting laguage you are using. You can create a Javascript array to send to the grid or create an XML data stream for the grid, that choice is yours and your choice might be effected by the database you are using (it might not be able to export XML easily).

For a Javascript array, make your data look like:

var myData = [["data","data","data"], ["data","data","data"]]


this is a simple example of data that would produce a grid with 2 rows and 3 columns.
Jim Hunter (www.FriendsOfAW.com)
March 1,
A sample of how to use mysql is posted here:

http://www.activewidgets.com/javascript.forum.12393.0/simple-php-mysql-example.html
Jim Hunter (www.FriendsOfAW.com)
March 1,

This topic is archived.

See also:


Back to support forum