$color = 'blue'
$ix = (array_search($color, $array))
{
if($ix !== FALSE)
{
if(array_key_exists($ix + 1, $array))
{
echo "Next after $color is: " . $array[$ix + 1];
}
else
{
echo "There is no color after $color.";
}
}
else
{
echo "There is no color $color in the array";
}
}
Note: this assumes an array indexed with sequential numbers. If it is not, then you could probably do it with a foreach loop and the next() function.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Allows for both arrays indexed with sequential numbers and with defined keys:
PHP Code:
$color = 'blue';
if (in_array($color, $array))
{
while (current($array) != $color)
{
next($array);
}
}
else
{
echo "There is no color $color in the array";
}
It's probably going to get really confusing if I try to explain what your current code is doing, I'd suggest using replacing your current code with the following:
PHP Code:
$sql_next = "select id, page_name from tp_pages WHERE group_='GeneralPlanning'";
$result_next = mysql_query($sql_next);
$row_next = mysql_fetch_array($result_next, MYSQL_NUM);
And now you may use either mine or NogDog's code to show the next element in the array result.
well it seams that I got real confused now one way or another.
I'm getting something wrong here. the script gives me the same info as the curent row, and not the next row. also if my row has id, page_name im getting page name outputed insted of id, plus its is the page name of curent row id.
So say actuall data look like this:
45, Fin Data
46, Address
when I set curent row as 45, the next row outut says Fin data, instead of 46
PHP Code:
$sql_next = "select id, page_name from tp_pages WHERE group_='GeneralPlanning'";
$result_next = mysql_query($sql_next);
$row_next = mysql_fetch_array($result_next, MYSQL_NUM);
///
$color = '45';
if (in_array($color, $row_next)){
while (current($row_next) != $color){
next($row_next);
}
}else{
echo "<br>There is no color $color in the array";
}
echo "<br>Next after $color is: <b>" . next($row_next) ."</b>";
Bookmarks