|
Posted by Jerry Stuckle on 11/13/07 18:14
floortje4@gmail.com wrote:
> On 13 nov, 15:13, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>
>>>> In this case, create a userlist class and let it perform the select
>>>> statement, building a new userobject for each row.
>
> After re-reading your reply im guessing we are not talking about the
> same thing. Im talking about a join of 2 tables: users and
> forum(entries). Im not quite sure where the userlist fits in. I have
> allready performed the select statement joing the two tables and I
> have all the data I need. Ater getting all the data I need I would
> like to make use of the handy classes I have created. Are you saying
> that I should pass specific data from each row to 2 new objects (class
> User and class Forum).
>
> Arjen
>
>
As an example:
class User {
private $userId;
function __construct($userId = null) { // To allow for a new user
$this->userId = $userId;
}
function getUserId() {
return $this->userId;
}
function setUserId($userId) {
// Validate it as necessary
// You can also return true/false depending on if
// validation succeeds or fails
$this->userId = $userId;
}
// ... other functions
}
class UserList {
private $users;
function __construct () { // Initialize the array
$users = array();
}
function fetchForumUsers($db) {
$userIds=$db::select('SELECT UserId FROM forum');
foreach ($userIds as $userId) {
// This does NOT execute a new SELECT statement!
$this->users[]=new User($userId);
}
function fecthUsers() {
return $this->users;
}
// ... other functions
// I often also add first(), last(), next() and prev() functions here
}
$userList = new UserList();
$userList->fetchForumUsers();
$users = $userList->fetchUsers();
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|