Array manipulation Q?
Posted: Mon Jan 12, 2004 2:55 pm
Hi,
I have a numerical array returned with a SELECT:
(9,7,6,5,4,3,1)
These numbers represent dates- with 9 being the most current, 1 the oldest. I'm unclear how to manipulate and access the individual elements in that array. I'm trying to set a couple of variables based on this array, and I've been futzing for days on it with no success.
Here's some code that shows what I'm trying to do:
$snap is the "date" I'm looking at, in this case 5.
The SELECT is fine and I can echo my array, but I can't set $next or $prev.
I want to set $next to be 4 and $prev to be 6 (for when $snap is 5 as in this example) . The array won't always have consecutive numbers, so just adding to $snap is not an option.
Any ideas how?
Thanks for any one who takes a whack at this - I hope it makes sense,
gord
I have a numerical array returned with a SELECT:
(9,7,6,5,4,3,1)
These numbers represent dates- with 9 being the most current, 1 the oldest. I'm unclear how to manipulate and access the individual elements in that array. I'm trying to set a couple of variables based on this array, and I've been futzing for days on it with no success.
Here's some code that shows what I'm trying to do:
Code: Select all
<?php
$snap=5;
$nav_sql = 'SELECT snapdate.date_id'
. ' FROM snapdate, snapshot'
. ' WHERE snapshot.owner =1 AND security_id =8 AND snapdate.date_id = snapshot.date_id'
. ' ORDER BY date_id DESC ';
$nav_result = MySQL_query($nav_sql);
$num = mysql_numrows($nav_result);
$i=0;
while ($i < $num) {
$date_id = mysql_result($nav_result,$i,"date_id");
++$i;
if ($date_id == $snap) {
$next = next($date_id);
$prev = prev($date_id);
}
}
?>The SELECT is fine and I can echo my array, but I can't set $next or $prev.
I want to set $next to be 4 and $prev to be 6 (for when $snap is 5 as in this example) . The array won't always have consecutive numbers, so just adding to $snap is not an option.
Any ideas how?
Thanks for any one who takes a whack at this - I hope it makes sense,
gord