tony_p Posted March 12, 2013 Share Posted March 12, 2013 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 Link to comment https://forums.phpfreaks.com/topic/275569-combo-dropdown-list-does-not-affect-result/ Share on other sites More sharing options...
akphidelt2007 Posted March 13, 2013 Share Posted March 13, 2013 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 https://forums.phpfreaks.com/topic/275569-combo-dropdown-list-does-not-affect-result/#findComment-1418297 Share on other sites More sharing options...
tony_p Posted March 13, 2013 Author Share Posted March 13, 2013 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 Link to comment https://forums.phpfreaks.com/topic/275569-combo-dropdown-list-does-not-affect-result/#findComment-1418397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.