Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zuma022

macrumors regular
Original poster
May 18, 2008
129
0
I recently posted, but the discussion went so far over my head I stayed out of it. :)
I'm just a newbie, currently taking a course. I've run into a problem that I just can't seem to solve, I don't understand why it won't work and I was hoping someone would be able to help.

Basically I have a database capturing entered tasks and I want to display them on an xtpl created page.
Here's the code. I assume it's not the prettiest, but I'm only concerned with getting it working right now, so if you see any obvious problems please let me know.

Here's the loop to display the tasks:
$getTasks = new task();

$getTasks->getTaskList('I', 'DESC');
$i = 0;
while ($aryRowI = $getTasks->getNextTask()) {

$incompleteTasks = array ('ROWNUMBER'=> ++$i,
'USER'=>$aryRowI['FirstName'] . ' ' . $aryRowI['LastName'],
'TASK'=>$aryRowI['TaskText'],
'TIMEDATE'=>$aryRowI['DateTimeStamp'],
'PRIORITY'=>$aryRowI['Priority'],
'DUEDATE'=>$aryRowI['DueDate']
);

$xtpl->assign('INCOMPLETE', $incompleteTasks);

}



These are the two methods within the task class that are relevant:

public function getTaskList($strStatus, $strOrder)
{

if (!$this->taskListDB) $this->taskListDB = new DB(DATABASE);

$strSqlQuery = 'SELECT tasks.ID, FirstName, LastName, UserID, DateTimeStamp, DueDate, Priority, TaskText, Completed
FROM tasks
JOIN users
ON tasks.UserID = users.ID';

$strSqlQuery = $strSqlQuery . ($strStatus == 'C' ? ' WHERE Completed ' : '');
$strSqlQuery .= $strStatus == 'I' ? ' WHERE NOT Completed ' : '';
$strSqlQuery .= " ORDER BY DateTimeStamp $strOrder ";

$this->taskListDB->execQuery($strSqlQuery);

}

public function getNextTask()
{

$this->aryTask = $this->taskListDB->fetchRow();
return $this->aryTask;
}

public function getTask()

{
return $this->aryTask;
}

Running this I get one row displayed. It appears to be just a random row too. Any help would be much appreciated, it's driving me nuts. Thank you!
 
All these:

$xtpl->assign('INCOMPLETE', $incompleteTasks);
new DB(DATABASE)
$this->taskListDB->execQuery($strSqlQuery);

...are referenced but not included in your code. Not only that, your description of what is wrong is vague. So even if you posted the whole thing, explain in simple terms what it does, and the output you expect. If the source is lengthy, file attach as .txt

-jim
 
All these:

$xtpl->assign('INCOMPLETE', $incompleteTasks);
new DB(DATABASE)
$this->taskListDB->execQuery($strSqlQuery);

...are referenced but not included in your code. Not only that, your description of what is wrong is vague. So even if you posted the whole thing, explain in simple terms what it does, and the output you expect. If the source is lengthy, file attach as .txt

-jim

Yeah, in general, when asking for help with a programming topic, do the following:

1) State what you expect to happen
2) State what actually happened
3) Post the smallest possible piece of code which contains this problem.

Step #3 is important. Remove the parts of the code that don't matter to your problem. A lot of times, you will answer your own question in the process of doing this because the process of simplifying makes the error much more obvious. This is the best way to learn.
 
Thanks for the replies. I was going to include the missing code and just as Savar suggested I figured out the problem. I assumed the problem was the loop, because I only got one row instead of all of them, but there actually was an xtpl assign problem which I was able to solve as soon as I looked up the code. Thanks guys, I still have a long way to go with OOP.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.