Forums / General / How to get instance of Database
bipul kuri
Wednesday 20 October 2004 2:06:20 am
I have created a database in Mysql say test and have created a table Employee with fields Name,Id,Dept. Now I want to generate a table in the template file to show the user. All I could make out from the forums and Documentations is to do this $db =& eZDB::instance(); $rows =& $db->arrayQuery( "SELECT * FROM employee" ); foreach ( $rows as $row ) { print( $row["name"] ); }}
but how do i know eZDB is connecting to my "test" databaseis this the correct way of getting the instance of database
Björn X
Wednesday 20 October 2004 2:17:01 am
I think you are missing here some basic concepts of eZ. Sorry to say that.
I would handle this like this:
-Create a new persistent object Employee-Create a new module function that is fetchable (operator fetch) within your template...
hmmm maybe I can give you the advice to buy the book. In the book should be all the code examples you need.
Łukasz Serwatka
Wednesday 20 October 2004 8:19:27 am
- in administration panel u can also create class called Employee with Name, Id, Dept attributes - create folder where u will store your objects- fatch data with fetch function
{section loop=fetch(content, list, hash(parent_node_id, $node.node_id))} {$:item.name} | {$:item.id} | {$:item.dept} {/section}
You can construc table in html with 1 object per row
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> Name </td> <td> Id</td> <td> Dept </td> </tr> {section loop=fetch(content, list, hash(parent_node_id, $node.node_id))} <tr> <td>{$:item.name}</td> <td>{$:item.id}</td> <td>{$:item.dept}</td> </tr> {/section} </table>
Personal website -> http://serwatka.net Blog (about eZ Publish) -> http://serwatka.net/blog
Wednesday 20 October 2004 10:12:56 pm
Thnak you all for the advice ,Is there any way to show an excel sheet embedded in the page or template not the file link because I have a Excel sheet which is updated by third party .