1

I have a table controlled by a dropdown box. My dropdown for example has all animals, lion, crocodile, and wolf. When I press lion results show fine, I then click crocodile and again results are fine but when I click the browser back button I can no longer see the previous results. What I want is after I click crocodile to be able to click the browser button and it to show previous results from the lion I clicked here is my code so far: I have also tried storing as local storage to no avail. The session is collected and posted onto a separate page that filters with this dropdown code. Bottom session code is what will display into a table.

<form id='id' method='GET' name='myform'> 
<!--<select name='fetching' class='filter' id='fetching' onchange = "getSelectValue()">  -->
<select name='fetching' class='filter' id='fetching'> 
    <option selected='true' disabled='disabled'>Select option </option> 
    <option value='All'>All</option> 
    <optgroup label='rare'>
    <?php
    $s = "SELECT DISTINCT species,status from animal"; 
    $result = $con->query($s);
    if($result = mysqli_query($con, $s)){
        if(mysqli_num_rows($result) > 0){
            while($row = mysqli_fetch_array($result)){
                if($row['status']=='rare'){
                    $output = "<option value='".$row['species']."'";    //keeps select option on dropdown the same upon page refresh
                    if($_GET['fetching'] == $row['species']){
                         $output .= " selected='selected'";
                    }
                    $output .= ">".$row['species']."</option>";
                    echo $output;
                    if($_GET['fetching']){
                        // $output .= " selected='selected'";
                        $_SESSION['animal'] = $_GET['fetching'];
                        header("Location: room.php?pn=1"); //added 12.04.22
                        exit;
                    }
                }
            }
        }
    }


    if (($_SESSION['animal']) =='lion') 
{
  $result = mysqli_query(
    $con,
    "SELECT * FROM `animal` WHERE species='lion' and gender='female' $limit"); 
}
    ?> 

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.