Getting Next item in array in a foreach loop
Posted: Sat Jan 14, 2006 12:27 pm
Hi,
I'm trying to generate a sort routine using a sortid in a database with up and down buttons to move items up and down in the list. This is fairly common, but I'm a little confused on how to do this.
I've gotten the up button to work fine by grabbing the previous item array, but how can I grab the next item in the array to get the id?
Thanks,
I'm trying to generate a sort routine using a sortid in a database with up and down buttons to move items up and down in the list. This is fairly common, but I'm a little confused on how to do this.
I've gotten the up button to work fine by grabbing the previous item array, but how can I grab the next item in the array to get the id?
Thanks,
Code: Select all
<?
foreach ($DB->all_rows AS $product) {
$THISPRODUCT = new ProductX;
$THISPRODUCT->id = $product['id'];
$THISPRODUCT->GetById();
?>
<tr>
<td><? if ($UPONE) echo "[<a href='swap.php?id1=$UPONE&id2={$THISPRODUCT->id}'>up</a>]"; ?><br />
[down]</td>
<td><? echo $THISPRODUCT->title; ?></td>
<td><a href="editproductx.php?id=<? echo $THISPRODUCT->id; ?>">Edit</a></td>
</tr>
<?
$UPONE = $product['id'];
}
?>