:: Forum >>

PHP MySQL Example Errors

Hi, I'm trying to pull data from a MySQL database using PHP and the example at http://www.activewidgets.com/grid.examples/php-mysql.html. While I do see my recordset populated into a JSON table in the generated HTML, the grid does not display at all and I've found the following issues, the first has been resolved but I am stuck on the second one:

1. These two lines are incorrect (or don't work in Firefox at least):

var myHeaders = <?= aw_headers($dataset) ?>
var myCells = <?= aw_cells($dataset) ?>

They both give me an invalid xml error in the error console, these changes in bold fixed this issue:

var myHeaders = <?php aw_headers($dataset) ?>
var myCells = <?php aw_cells($dataset) ?>

2. This line also gives an error:

echo "[".implode(",",$cols)."];\n";

Error reported in error console and generated in html:

Error console: Invalid flag after regular expression

HTML:
<b>Warning</b>: implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in <b>C:\htdocs\mewp\aw_dyncontacts.php</b> on line <b>59</b><br />

I'm fairly new to php, mysql, and javascript and I'm a bit lost here - any ideas?
Jeremy Savoy
Saturday, January 19, 2008
The example is working fine for me.
That error might be because $cols is empty at that line which could be because it couldn't fetch any data from the database.
Have you setup the databse and the table properly ?
Is the database name, username and password set correctly ?
Also, does your table have data in it ?
Ankur Motreja
Saturday, January 19, 2008
Forgot to mention, I didn't get the first error you mentioned (about <?= having to be replaced with <?php)
The example worked fine without this change.
Which version of PHP do you have ?
I tried it with versions 5.2.1 and 4.4.6
Ankur Motreja
Saturday, January 19, 2008
Yes, the db is set up correctly and I can pull data using other php code with no problem. I'm using PHP 5.2.5.

For now, I've implemented PHP code to export my table to XML, and I call that PHP function directly when I create the AW Grid using an xml table.

// create ActiveWidgets data model - XML-based table
var table = new AW.XML.Table;
// provide data URL
table.setURL("xml/contacts_xml.php");

The problem that this gives me is that I will have a hard time refreshing only one line of the grid each time I add a row, because I will have to add the data to the database, and then regenerate the xml and the grid completely. Otherwise if I update the xml and the database seperately, then the entry in xml and the grid will not contain the primary key (hidden in the grid), and I will have a hard time trying to update an entry in the future without the primary key. Any ideas?
Jeremy Savoy
Monday, January 21, 2008
There is a parameter in PHP configuration, which disables <?= ...?> syntax. Unfortunately I no longer remember which one (just saw it once long time ago).
Alex (ActiveWidgets)
Monday, January 21, 2008
Thanks Alex, any advice on updating MySQL DB and the table (xml created from MySQL table using php) without refreshing the entire grid, since each table entry (i.e. xml entry and grid entry) need to contain the Primary Key in order for future edits that may occur before the grid was fully refreshed/reloaded from the DB?

I'm guessing something like this:

// newContact function
function newContact(){

// Add code here to popup a dialog (maybe AW dialog??) to get required data for new
// contact and then write that data to MySQL db after entered in dialog box

// Add code here to retrieve Contact_ID of new contact (primary key)

// And here is the stuff to refresh only the xml object and grid:
// calc new row index
var i = table.length;

// add row to the datasource
table[i] = ["Contact_ID" + "First Name", + "etc, etc etc"];

// update grid
obj.addRow(i);
}
    
// New Contact Button
var addContactButton = new AW.UI.Button;
addContactButton.setControlText("New Contact");
addContactButton.onControlClicked = newContact;


I think this would work -- any advice/ideas/opinions before I start coding?
thx
Jeremy Savoy
Monday, January 21, 2008

This topic is archived.


Back to support forum

Forum search