php dom and KompoZer
Posted: Tue Aug 03, 2010 2:42 am
Hello
I am fairly new to php although have done more on other languages.
What I was looking for was a simple way to use a GUI designer and also use php and mysql to populate tables.
Any suggestion would be good although I have done some investigations.
The mechanism I have use is as follows.
In KompoZer design you html page (Template.html) with a table and give the first data row a unique ID ie id="row1table1"
For example
[text]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Template</title>
</head>
<body>
<table style="text-align: left; width: 100%;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr id="row1table1">
<td>Jim</td>
<td>21</td>
<td>UK</td>
</tr>
</tbody>
</table>
</body>
</html>[/text]
Then use some PHP DOM code to retrieve the DOM row object, clone it, alter it's fields and append to the table
As follows
Above is a simple example but you could see how it could be expanded to populate a table from a database.
Also I think any GUI designer could be used, as long as the idea of row id="row1table1" is used.
Any other ideas
Thanks
Jim
I am fairly new to php although have done more on other languages.
What I was looking for was a simple way to use a GUI designer and also use php and mysql to populate tables.
Any suggestion would be good although I have done some investigations.
The mechanism I have use is as follows.
In KompoZer design you html page (Template.html) with a table and give the first data row a unique ID ie id="row1table1"
For example
[text]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Template</title>
</head>
<body>
<table style="text-align: left; width: 100%;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr id="row1table1">
<td>Jim</td>
<td>21</td>
<td>UK</td>
</tr>
</tbody>
</table>
</body>
</html>[/text]
Then use some PHP DOM code to retrieve the DOM row object, clone it, alter it's fields and append to the table
As follows
Code: Select all
<?php
/*** a new dom object ***/
$dom = new domDocument;
/*** load the html into the object ***/
$dom->loadHTMLFILE('Template.html');
/*** get the row object ***/
$templateRow=$dom->getElementById("row1table1");
/*** determine it's parent ***/
$parent=$templateRow->parentNode;
/*** clone the row ***/
$newRow=$templateRow->cloneNode(true);
/*** alter it's fields as required ***/
$newRow->childNodes->item(0)->nodeValue="Fred";
$newRow->childNodes->item(2)->nodeValue="36";
$newRow->childNodes->item(4)->nodeValue="Italy";
/*** append the row to the table, tbody in this case ***/
$parent->appendChild($newRow);
/*** convert dom back to html and output page ***/
$str = $dom->saveHTML();
echo $str;
?>
Also I think any GUI designer could be used, as long as the idea of row id="row1table1" is used.
Any other ideas
Thanks
Jim