3.2.0

help in PHP - ActivwWidgets

Hi,

I am using PHP-MySQL,Activewidgets.

I have 11 column in my MySql table. i want to concatenate 2 to 11 column and put the value in 1st column for that i have written following code in javascript

// Concatenate columns and put values in column 0

function Con(column,row)
{

return String((this.getCellValue(1,row)) + (this.getCellValue(2,row)) + (this.getCellValue(3,row)) + (this.getCellValue(4,row)) + (this.getCellValue(5,row)) + (this.getCellValue(6,row)) + (this.getCellValue(7,row)) + (this.getCellValue(8,row)) + (this.getCellValue(9,row)) + (this.getCellValue(10,row)));
}
obj.setCellData(Con,0);

This function doesn't work in PHP but if tried this function in Asp.Net it is working fine.

Please help me.
Harsh
September 13,
I don't see any errors here - maybe the problem is somewhere else?
Alex (ActiveWidgets)
September 13,
Hi Alex,

This is my full code please check it out may be you can fix the error.

<?php

$connection = @mysql_connect('localhost', '', '');
@mysql_select_db('rocom', $connection);
$query = 'SELECT * FROM rocom_data';
$dataset = @mysql_query($query, $connection);


// print MySQL query results as 2D javascript array
function aw_cells($dataset){

$rows = array();
while ($record = @mysql_fetch_row($dataset)) {
$cols = array();
foreach ($record as $value) {
$cols[] = '"'.addslashes($value).'"';
}
$rows[] = "\t[".implode(",", $cols)."]";
}
echo "[\n".implode(",\n",$rows)."\n];\n";
}

// print MySQL field names as javascript array
function aw_headers($dataset){
while ($field = @mysql_fetch_field($dataset)) {
$cols[] = '"'.$field->name.'"';
}
echo "[".implode(",",$cols)."];\n";
}

?>
<html>
<head>
<!-- include AW stylesheet and script -->
<link href="ActiveWidgets/runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>

</head>
<body>
<font face="Arial" size="3"><small><b>Click on a column heading to sort by that variable.</b></small></font>
<!--ActiveWidgets stylesheet and scripts -->
<script src="ActiveWidgets/runtime/lib/aw.js"></script>

<STYLE>
.aw-alternate-even { BACKGROUND: #ebf5fb }
.aw-alternate-odd { BACKGROUND: #ffffff }
.aw-column-0 { TEXT-ALIGN: center }
.aw-column-1 { TEXT-ALIGN: center }
.aw-column-2 { TEXT-ALIGN: center }
.aw-column-3 { TEXT-ALIGN: center }
.aw-column-4 { TEXT-ALIGN: center }
.aw-column-5 { TEXT-ALIGN: center }
.aw-column-6 { TEXT-ALIGN: center }
.aw-column-7 { TEXT-ALIGN: center }
.aw-column-8 { TEXT-ALIGN: center }
.aw-column-9 { TEXT-ALIGN: center }
.aw-column-10 { TEXT-ALIGN: center }
.aw-column-11 { TEXT-ALIGN: center }
.aw-column-12 { TEXT-ALIGN: center }
.aw-column-13 { TEXT-ALIGN: center }
.aw-column-14 { TEXT-ALIGN: center }
.aw-column-15 { TEXT-ALIGN: center }
.aw-column-16 { TEXT-ALIGN: center }
.aw-column-17 { TEXT-ALIGN: center }
.aw-column-18 { TEXT-ALIGN: center }
.aw-column-19 { TEXT-ALIGN: center }
.aw-column-20 { TEXT-ALIGN: center }
.aw-column-21 { TEXT-ALIGN: center }
.aw-column-22 { TEXT-ALIGN: center }
.aw-column-23 { TEXT-ALIGN: center }
.aw-column-24 { TEXT-ALIGN: center }
.aw-column-25 { TEXT-ALIGN: center }
.aw-column-26 { TEXT-ALIGN: center }
.aw-cells-selected { BACKGROUND: #efaaaa; COLOR: #111 }
.aw-rows-selected { BACKGROUND: #efaaaa; COLOR: #111 }
</STYLE>
<script>

// insert javascript arrays produced by PHP functions
var myHeaders = <?= aw_headers($dataset) ?>
var myCells = <?= aw_cells($dataset) ?>

// create grid control
var obj = new AW.UI.Grid;

// set grid text
obj.setHeaderText(myHeaders);
obj.setCellText(myCells);

// set number of columns/rows
obj.setColumnCount(myHeaders.length);
obj.setRowCount(myCells.length);



// define the width of the columns

var columnIndices="0,"; //for later use
obj.setFixedLeft(1);

if(obj.getColumnCount() > 10)
width = 60;
else
width = Math.round((575 - obj.getColumnWidth(0) - obj.getColumnWidth(1))/(obj.getColumnCount() - 2) - 1);
for(var i=1;i<obj.getColumnCount();i++)
{
obj.setColumnWidth(width,i);
columnIndices = columnIndices + i +",";
}
obj.setColumnWidth(width,i);
obj.setColumnWidth(160,0);
obj.setColumnWidth(70,18);
obj.setColumnWidth(75,8);
obj.setColumnWidth(95,9);
obj.setColumnWidth(95,12);
obj.setColumnWidth(100,13);
obj.setColumnWidth(65,14);

// Grid:
obj.setSize(1200,560);

// Headers:
obj.setHeaderCount(1);
//obj.setHeaderHeight(65);

obj.setSelectionMode("multi-row");

// Concatenate columns and put values in column 0

function sum1(column,row)
{
return string((this.getCellValue(1,row)) + (this.getCellValue(2,row)));
}
obj.setCellData(sum1,0);

// write grid to the page
document.write("<br>" + "<br>" + obj);

</script>
</body>
</html>

Harsh
September 14,
This code looks bad -

function sum1(column,row)
{
return string((this.getCellValue(1,row)) + (this.getCellValue(2,row)));
}

Javascript is case sensitive, so 'string' is not the same as 'String' and will trigger an error.
Alex (ActiveWidgets)
September 14,
I appreciate your suggestion, we tried your solution but it doesn't work.
But we found a way to do this, please look at these PHP function

$cols[0] = '"'.addslashes($cols[1]).addslashes($cols[2]).addslashes($cols[3]).addslashes($cols[4]).addslashes($cols[5]).addslashes($cols[6]).addslashes($cols[7]).addslashes($cols[8]).addslashes($cols[9]).addslashes($cols[10]).'"';

$cols[0] = ereg_replace("[^A-Za-z0-9]", "", $cols[0]);

Thanks.
Harsh
September 15,

This topic is archived.

See also:


Back to support forum