Possible Duplicate:
PHP foreach() return only last 50 items
I need only the last 2 record from it. The code below return all the records. thank you
<?php
foreach ($fields as $field) {
$type = $field['s_type'];
$label = $field['s_label'];
$value = Attributes::newInstance()->getValue($item_id, $field['pk_i_id']);
if ($type == 'checkbox') {
if ($value == 'checked') $value = 'Yes';
else $value = 'No';
}
?>
<tr>
<td style='width: 150px;'><?php _e($label, pg); ?></td>
<td style='width: 150px;'><?php _e($value, pg); ?></td>
</tr>
<?php } ?>
Can you use array_slice with -2 as the second parameter?
You can use array slice to manage the fields before iterating.
$last_two = array_slice($fields, -2);
foreach($last_two as $field) { ... }
Although if this is the only thing being done in this script I would suggest rewriting your query structure.