Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/117987-array-help/
Share on other sites

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>";
?>

Link to comment
https://forums.phpfreaks.com/topic/117987-array-help/#findComment-607008
Share on other sites

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'>&raquo ".$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...

Link to comment
https://forums.phpfreaks.com/topic/117987-array-help/#findComment-607025
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.