:: Forum >>

Setting text in grid from a php variable

I am trying to use a php array variable to set the text for a grid. However I keep getting the error message

"Undefined index i at line - ***obj.setDataText(function(i, j){return $myData[i][j]});"

The below code will work fine when I have a var array like the one used for myColumns below. However, the text I want to put into the grid is a php array variable $mydata;

Is there any way round this? Can I convert the php array to a var array? Or can I access the php array inside the script tags to set the text in the grid?

Any help will be greatly appreciated!

<?php
$myData = array(
array("MSFT","Microsoft Corporation", "314,571.156", "32,187.000", "55000"),
array("ORCL", "Oracle Corporation", "62,615.266", "9,519.000", "40650"),
array("SAP", "SAP AG (ADR)", "40,986.328", "8,296.420", "28961"),
array("CA", "Computer Associates Inter", "15,606.335", "3,164.000", "16000"),
array("ERTS", "Electronic Arts Inc.", "14,490.895", "2,503.727", "4000"),
array("SFTBF", "Softbank Corp. (ADR)", "14,485.840", ".000", "6865"),
array("VRTS", "Veritas Software Corp.", "14,444.272", "1,578.658", "5647"),
array("SYMC", "Symantec Corporation", "9,932.483", "1,482.029", "4300"),
array("INFY", "Infosys Technologies Ltd.", "9,763.851", "830.748", "15400"),
);

echo "<script>
var obj = new Active.Controls.Grid;
obj.setRowCount(9);
obj.setColumnCount(9);
var myColumns = ['Item', 'Product Code', 'Description', 'Quantity', 'Unit Price', 'Project Code', 'Sub Anaysis', 'VAT Code', 'Total Price (Excl VAT)'];
obj.setColumnText(function(i){return myColumns[i]});
***obj.setDataText(function(i, j){return $myData[i][j]});
document.write(obj);
</script>";
?>
carbine
Tuesday, March 22, 2005
foreach ($rows as $row)
{
$first = $row['first'];
$last = $row['last'];
$phone = $row['phone'];
$jsrows[] = '["' . join('", "', array($first, $last, $phone)) . '"]';
}
$jsrows = '[' . join(",\n", $rows) . ']';

Now you can use $jsrows as you javascript array value.

var myData = <?php echo $jsrows; ?>;
mysticweb.org
Thursday, March 24, 2005
Sorry. Should be --

$jsrows = '[' . join(",\n", $jsrows) . ']';
mysticweb.org
Thursday, March 24, 2005

This topic is archived.


Back to support forum

Forum search