Friday, January 23, 2009

Calling Any PHP Programmers

If you know PHP, I could use your help. I've got some code that's not functioning as expected. I am attempting to break some data extracted from MySQL into three sections. The relevant segment of code is below:

function Row1() {
$Part = ceil(($this->Articles()->Count()) / 3);
return DataObject::get("ArticlePage", "", "", "", "0, $Part");
}
function Row2() {
$Part = ceil(($this->Articles()->Count()) / 3);
$Part2 = floor(($Part * 2));
return DataObject::get("ArticlePage", "", "", "", "$Part, $Part2");
}
function Row3() {
$Total = ($this->Articles()->Count()) ;
$Part = ceil(($Total / 3)); $Break = ceil(($Part * 2));
return DataObject::get("ArticlePage", "", "", "", "$Break, $Total");
}
}

Row 1 displays the first third of the results. Row 3 displays the last third of the results. Row 2, however, is displaying the second third all the way to the end.

Example: Let's say there are 6 items.

Row 1
Item 1
Item 2
Row 2
Item 3
Item 4
Item 5
Item 6
Row3
Item 5
Item 6

Click Here to see the actual output.

Any ideas why it's breaking down like that? The calculation for $Part2 should be correct since it's the same as $Break and Row 3 is starting in the correct place. I'm not a PHP programmer so I can only assume the last parameter in the Get statement indicates "start, end"

I would also like to alphebetize the list but I haven't even started on that yet.

UPDATE: I figured out what my problem was. I was assuming that the last parameter meant starting record number, ending record number when in actuality it means starting record number, number of records to display. It works now!

No comments: