EllisLab text mark
Advanced Search
     
check if last on last row?
Posted: 14 August 2012 05:23 AM   [ Ignore ]
Joined: 2011-10-28
56 posts

Hello,

using the active records or any other database function is there a way to do an if statement to see if you are on the last row in the result yet or not? Basically I want to add a comma to all lines except the last one… something like this:

<?php foreach($images->result() as $image): ?>
    {image
:'images/gallery/'.$id.'/<?php echo $image->file; ?>'thumb'images/gallery/'.$id.'/thumbs/<?php echo $image->file; ?>'}<?php if ($images->current_row() < $images->num_rows()): ?>,<?php endif; ?>
<?php 
endforeach; ?> 

I can’t find anything that will say current row though. do I gotta make the code ugly and add in a counter/ do it myself???

 

 
Posted: 14 August 2012 11:22 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2010-06-27
134 posts

try this approach:

<?php 
$obj 
$images->result();
foreach(
$obj as $image): 
?>
    {image
:'images/gallery/'.$id.'/<?php echo $image->file; ?>'thumb'images/gallery/'.$id.'/thumbs/<?php echo $image->file; ?>'}<?php if ($image != end($obj): echo ','; endif; ?>
<?php 
endforeach; ?> 
 Signature 

“I Reject Your Reality and Substitute My Own” - Adam Savage, M5 Inc