Re: Browse database records

From: Date: Sun, 28 Oct 2001 16:31:13 +0000
Subject: Re: Browse database records
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-2427@lists.php.net to get a copy of this message
I'm working on something like that. It's in alpha state so I haven't published it yet (if someone's interested I'd like to contribute it). It's based on the DB and IntegratedTemplate classes and works (or should work ;-)) like that:
I will not be available during 3 weeks for professional reason. Then, I will be delighted to help you on the subject.
    $stmt = new IFW_DBSelectGenerator();
    $stmt->addField("*");
    $stmt->addTable("user");
    $stmt->addFilter("username LIKE 'a%'");
    $stmt->addSort("username");
    $grid = new IFW_DBGrid(TEMPLATE_PATH, "userlist.tpl", $stmt);
    $grid->setPageSize(10);
    $grid->show();
Page handling and sorting is done automatically. There are special variables you can integrate in the template (ROWNO, ROWCOUNT, ROWMIN, ROWMAX, <fieldname>, URL_SORT_<fieldname>, ...). Here's a template example: Rows {ROWMIN}-{ROWMAX} from {ROWCOUNT}, page {PAGENO} from {PAGENOMAX} <table border=1 cellpadding=0 cellspacing=0 borderwidth=0 bgcolor=#aaaaaa> <tr><td> <table border=0 cellpadding=0 cellspacing=3 borderwidth=0>
    <tr>
      <td rowspan=2>
        <table border=1 bgcolor=#ffffff width=400>
          <tr bgcolor=#dddddd>
            <th>&nbsp;</th>
            <th><a href="{URL_SORT_USERNAME}">Name</a></th>
            <th><a href="{URL_SORT_SURNAME}">Full Name</a></th>
            <th>Department</th>
            <th>Location</th>
          </tr>
          <!-- BEGIN listrow -->
          <tr>
            <td>{ROWNO}</td>
            <td><a
href="{URL_BASE}?module=user&action=edit&userid={USERID}">{USERNAME}</a></td>
            <td>{PRENAME} {SURNAME}</td>
            <td>{ORGUNITNAME}</td>
            <td>{LOCATIONNAME}</td>
          </tr>
          <!-- END listrow -->
        </table>
      </td>
      <td valign=top>
        <!-- BEGIN prevpage -->
        <a href="{URL_PREVPAGE}">[&lt;&lt;]</a>
        <!-- END prevpage -->
      </td>
    </tr>
    <tr>
      <td valign=bottom>
        <!-- BEGIN nextpage -->
        <a href="{URL_NEXTPAGE}">[&gt;&gt;]</a>
        <!-- END nextpage -->
      </td>
    </tr>
</table> </td></tr> </table>do
You should had a look at phplens classes which is a very good product I recommand. Everything is coded within a single interface object, no HTML. IMHO: - no html, coding should be done through objects, - when this works, we can map objects to database records to obtain a complete file-html-less solution. Best regards, Jean-Michel POURE

« previous php.pear.dev (#2427) next »