veroaero Posted August 3, 2008 Share Posted August 3, 2008 Hi, Here is my example: Say I have an array with id's of photos or something: 3,4,5,7,11. If I am currently looking at id=4, how do I get the whole array and their order so I know that id:4 is the second photo and 3 is the first etc and the last one is 11? (I get these results from my mysql database.) Thanks in advance, Vero Quote Link to comment https://forums.phpfreaks.com/topic/117987-array-help/ Share on other sites More sharing options...
Stooney Posted August 3, 2008 Share Posted August 3, 2008 try sort() http://us2.php.net/manual/en/function.sort.php Quote Link to comment https://forums.phpfreaks.com/topic/117987-array-help/#findComment-606997 Share on other sites More sharing options...
MadTechie Posted August 3, 2008 Share Posted August 3, 2008 i really need an example of what your doing but this should work <?php $C = 5; $a = array(3,4,5,7,11); $item = current($a); echo "start:"; echo key($item); echo "<br>"; while($item != $C) { $item = next($a); } echo "current:".key($item)."<br>"; echo "end:"; echo key(end($a)); echo "<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/117987-array-help/#findComment-607008 Share on other sites More sharing options...
veroaero Posted August 3, 2008 Author Share Posted August 3, 2008 i really need an example of what your doing but this should work Ok, here is my example: I am trying to build next/previous links for this code: In this example, I have the present id of the photo I am looking at, and I can get the rest of the photos in the same category, but they are not necessarily in order, can be id's like: 3, 4,5 7, 11. // Full Size View of Photo else if( $pid ) { $result = mysql_query( "SELECT photo_caption,photo_filename,photo_id FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" ); $row = mysql_fetch_array($result) or die(mysql_error()); $photo_caption = $row['photo_caption']; $photo_filename = $row['photo_filename']; $photo_id = $row['photo_id']; $nr = mysql_num_rows( $result ); if( empty( $nr ) ) { echo"\t Oj! Det finns inga foton i den här kategorin! \n"; } else { $result2 = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" ); $row2 = mysql_fetch_array($result2) or die(mysql_error()); $category_name = $row2['category_name']; $result3 = mysql_query( "SELECT photo_id FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" ); $row3 = mysql_fetch_array($result3); echo"<br><a class='pinkLink' href='daif_vimmel.php?cid=$cid'>» ".$category_name."</a><br>\n"; echo"<div class='fullviewbox'> \n <img class='fullview' src='".$images_dir."/".$photo_filename."' alt='".$photo_caption."' >\n <br>\n $photo_caption \n </div>"; } } // Final Output This might be a totally stupid question... Quote Link to comment https://forums.phpfreaks.com/topic/117987-array-help/#findComment-607025 Share on other sites More sharing options...
MadTechie Posted August 3, 2008 Share Posted August 3, 2008 The code i posted will work fine no matter what order of the array.. and i'm sorry but i can see how you have a next/prev in your current code.. maybe read up on "php pagination" for some examples as i think your trying to do this the hard way Quote Link to comment https://forums.phpfreaks.com/topic/117987-array-help/#findComment-607034 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.