Welcome Guest, Not a member yet? Register   Sign In
check if last on last row?
#1

[eluser]superfake123[/eluser]
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:

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

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???
#2

[eluser]Rolly1971[/eluser]
try this approach:

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




Theme © iAndrew 2016 - Forum software by © MyBB