Jump to content

combo dropdown list does not affect result


tony_p

Recommended Posts

I have this code below that creates a combo dropdown list that the user can use to select how many images ($MAXEMLEMENTSPERPAGE) I have set caption to be 1 the problem is I can't figure out how to get the combo box to change the value of the user selected item to show that the  number of images the user wants I am using $xml = simplexml_load_file ("xml/images.xml"); to load the image elements and then $maxpage to paginate the images if I change $cation to 5 then it displays 5 images per page the problem I have is at the moment I haven't found a way of passing the selected value to $caption to refresh the any help would be appriciated ::)

<select name="mydropdownlist">
	<?php
	$caption = 1;	                  
	
	$options = array('2' => '2',
							 '3' => '3',
							 '4' => '4');

			foreach($options as $value => $caption)
	   { 
				if(isset($_GET['caption']))
		{
			$caption = $_GET['caption'];   //if page is specif
		}
					echo "<option value=\"$value\" selected=\"$value\">$caption</option>";
					
	   }
	?>
 </select>
<?php
	$page = 0;
	$MAXELEMENTSPERPAGE = $caption; //change this value to display how many elements per page you wish people to see
	$maxPage = count($xml)/$MAXELEMENTSPERPAGE;

	if(isset($_GET['page']))
	{
		$page = $_GET['page'];   //if page is specif
	}

	?> <?php
	for($i =$page * $MAXELEMENTSPERPAGE ; $i< ($page * $MAXELEMENTSPERPAGE ) +$MAXELEMENTSPERPAGE ; $i++)
					{
						//start the foreach loop
						$imageProp = $i;

						if($i >= count($xml))
						{
							break;
						}
 ?>
 Page:
<?php
if($page > 0){
	?>
	<a href=<?php echo $_SERVER["PHP_SELF"]."?page=".($page-1); ?>>Previous </a>
	<?php
}

for($i = 0; $i< $maxPage; $i++ ){
	//here we are making a loop for how many pages we have
	//we then spawn a hyperlink for each page
	//$Server["php_self"]  returns the current page url
	//then we append the page number to it

	?>

	<a href=<?php echo $_SERVER["PHP_SELF"]."?page=".$i; ?>><?php echo $i;?></a>
	<?php
}
?>
<?php
if($page < floor($maxPage)){
	?>

	<a href=<?php echo $_SERVER["PHP_SELF"]."?page=".($page+1); ?>> Next </a>
	<?php
}
?>

 

page with its new value

Edited by tony_p
Link to comment
Share on other sites

Try something like this...

 

 

    $caption = isset($_GET['caption'])  ? $_GET['caption'] : 1;    
    
    $options = array('2' => '2',
                             '3' => '3',
                             '4' => '4');

            foreach($options as $value => $text)
     {
                    $selected = $caption==$text ? ' selected' : '';
                    echo "<option value='$value'$selected>$text</option>";
                    
     }

 

This is basically a shorthand method to simply create the $caption variable with out having to manipulate it so much through your foreach statement.

Link to comment
Share on other sites

I have tried several approaches but I seem to be missing some code as nothing I do changes the result when the user changes the value of the combo box the the number of elements shown per page stays the same or should I say the page does not get updated ::)

Edited by tony_p
Link to comment
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.