Jump to content

tony_p

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by tony_p

  1. I have a drop down form that the user selects to change the number of items shown per page

    <form id="pagesize" action="<?php $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']; ?>" method="get">
    <select class="paginate" name="caption" onchange="this.form.submit()"$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; ?>
    <option caption=4 value=4>4</option>
    <option caption=5 value=5>5</option>
    <option caption=10 value=10>10</option>
    <option caption=25 value=25>25</option>
    </select>
    </form>
    

     the  problem is that whenever someone perform a get request on the page the POST data disappears. Does anyone know any way in which we can solve this. We can post to the page fine, the print_r of post shows this when we head to the page: Array '/Search_form/search_results.php?photograpgher_id=1&photographer=x&image=x&Submit=Search&page=1' its only when we do a get request on the page we have a problem as the post data does not follow through with the get request we only get the this array '/Search_form/search_results.php?caption=5' but it should be '/Search_form/search_results.php?photograpgher_id=1&photographer=x&image=x&Submit=Search&page=1?caption=5' as I have type this in manually and works fine any help would be appreciated

     

     

     

     

     

     

     

     

     

  2. Sorry I forgot to add the XML content

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
        <area>
            <photographer_id>1</photographer_id>
            <photographer>John</photographer>
            <image>a</image>
        </area>
         <area>
            <photographer_id>1</photographer_id>
            <photographer>John</photographer>
            <image>b</image>
        </area>
         <area>
            <photographer_id>1</photographer_id>
            <photographer>John</photographer>
            <image>c</image>
        </area>
         <area>
            <photographer_id>2</photographer_id>
            <photographer>Fred</photographer>
            <image>a</image>
        </area>
    </root>

  3. XPATH method for retuning multiple dynamic results from a XML file using PHP
    I have a form that the user types or selects a value the form is as follows
    <form id="search_photos" action="photo_result.php" method="get">
        <input value="" name="photographer_id" id="photographer_id"  style=" border:1px solid Silver;" type="text">
        <select name="Photographer" id="Photographer"   style="height:23px; border:1px solid Silver;">
            <option selected="selected" value="x">Any Photographer</option>
            <option value="John">John</option>
            <option value="Fred">Fred</option>
            <option value="Joseph">Joseph</option>
        </select>
        <select name="images" id="images"   style="height:23px; border:1px solid Silver;">
            <option selected="selected" value="x">All Images</option>
            <option value="0">None</option>
            <option value="a">Image a</option>
            <option value="b">Image b </option>
            <option value="c">Image c </option>
        </select>
        <input name="Submit" value="Search Now >" id="Submit" class="Adv1_Filter_Button" type="submit">
    </form>

    Then the search_photo.php script  that catches the result of the form and filters the values entered by the user as

    follows
    <?php

       $xml = simplexml_load_file("photo.xml");
       
       for ($i = 0; $i < count($xml); $i++){  
     
        if(isset($_GET["LocationName"]))
        {
            $photographer_id = $_GET["LocationName"];
        }
        $result = $xml->xpath('/root/area[photographer_id=' . $photographer_id . ']  ');
        }
            
        if(isset($_GET["Photographer"]))
        {
            $photographer = $_GET["Photographer"];
        }
            $result = $xml->xpath('/root/area[photographer_id=' . $photographer_id . ']  ');

        if(isset($_GET["images"]))
        {
            $image = $_GET["images"];
            
            
       }
            
        echo $photographer_id;
        echo $photographer;
        echo $image;
        var_dump ($result);
        
        ?>
    The $result from the first XPATH pass is correct  if all that is set is ‘photographer_id’ if I then  try $result=$xml->xpath

    ('/root/area[photographer_id=' . $photographer_id . '] | /root/area[photographer=' . $photographer .']');  and  select

     1 and fred then I get the result of an array of all four when it should be an empty array I have trie & (and) insted of | (or) but just returns an empty array should I convert the $result to an object or is the a way of saving the $result to an xml file

     

  4. 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

×
×
  • 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.