Reputation: 1472
I am trying to find picid in array but it's not working. When I echo it, nothing appears.
Here is my code
<?php $psql=mysql_query("select * from gallery where userId='$miid'");
$photo1 = array();
while($photo=mysql_fetch_assoc($psql)) {
$photo1[]=$photo;
print_r($photo);
}
foreach($photo1 as $k => $v){
if($v['picId']==$mipic){
$pic="uploads/".$v['photo'];
echo ">>>". $key=array_search($v['picId'],$photo1);
?>
<a href="eg?next=<?php echo $photo[$k+1];?>">NEXT</a>
<img src="<?php echo $pic; ?>" width="300px" height="300px">
<a href="eg?previous=<?php echo $photo[$k-1];?>">PREVIOUS</a>
<?php
}
}?>
Upvotes: 1
Views: 99
Reputation: 13331
array_search is not recursive. $v
exists in $photo1
, while $v['picId']
only exists in $v
.
That makes $key=array_search($v['picId'],$photo1)
return false
which, when you echo it, will print as nothing.
I am not sure why you are using array_search
at all. In order to retrieve the next and previous picId, try this:
<a href="modules/gallery/miloader.php?next=<?php echo $photo1[$k+1]['picId'];?>">NEXT</a>
<img src="<?php echo $pic; ?>" width="300px" height="300px">
<a href="miloader.php?previous=<?php echo $photo1[$k-1]['picId'];?>">PREVIOUS</a>
Beware though that one of the hrefs is modules/gallery/miloader.php
while the other is just miloader.php
. So unless you actually have two different miloader.php files (one in each of the directories), one of them is wrong.
Upvotes: 1