RE: [PEAR] DB_DataObject how to iterate through a table?
| From: | Mike Carter | Date: | Mon, 16 Feb 2004 09:00:30 +0000 |
| Subject: | RE: [PEAR] DB_DataObject how to iterate through a table? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-10709@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Hakan Kücükyilmaz [mailto:hakan@php.net]
>
> I am testing DB_DataObject and wondering how to iterate
> through a table.
> What I tried is:
>
> $Termin = new DataObject_Termin();
>
> $Termin->find(TRUE);
> do {
> echo $Termin->termin_id , '<br />';
> echo $Termin->termin_titel, '<br />';
> echo $Termin->termin_datum, '<br />';
> echo '<br />';
> } while ($Termin->fetch());
>
> ----------------------
> Which iterates through the table 'Termin'. Does this approach has any
> drawbacks?
The PEAR DBO manual has an example of looping through a recordset.
http://pear.php.net/manual/en/package.database.db-dataobject.db-dataobject..f
etch.php
<?php
$person = new DataObjects_Person;
$person->hair = 'red';
$person->has_glasses = 1;
$number_of_rows = $person->find();
$people = array();
while ($person->fetch()) {
/* store the results in an array */
$people[] = clone($person);
echo "GOT {$person->name}<BR>";
}
?>
- Mike C.
________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________