Home » Php » print data from drop down menu

print data from drop down menu

Posted by: admin September 25, 2018 Leave a comment

Questions:

I create three-layer drop-down menu with php.I want to print out selected options of these dropdown lists when i submit.I don’t know how can i do , please help me

The files have php and get_country.php,
mysql columns (date,time,ip,country,status)

one-layer select date,two-layer is time and three-layer select country

php (drop-down menu)

<?php
require_once 'dbconnect.php';
$query   = "SELECT * FROM geo";
$results = mysqli_query($conn, $query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Select</title>
</head>    
<script src="https://code.jquery.com/jquery-2.1.1.min.js"   type="text/javascript"></script>
<script>
function getTime(val) {
$.ajax({
    type: "POST",
    url: "get_country.php",
    data:'date_id='+val,
   success: function(data){
    $("#time-list").html(data);
  }
  });
  }

  function selectRegion(val) {
  $("#search-box").val(val); 
  $("#suggesstion-box").hide();
  }

  function getcountry(val){
  $.ajax({
    type: "POST",
    url: "get_country.php",
    data:'time_id='+val,
   success: function(data){
    $("#country-list").html(data);
  }
  });
  }
  function selectRegion(val) {
  $("#search-box").val(val); 
  $("#suggesstion-box").hide();
  }


 </script>

 <body>
<div class="frmDronpDown">
<div class="row">

<form>
<label>Date: </label>
<select name="date" id="date-list" class="demoInputBox" onChange="getTime(this.value);">
    <option value="">Select date</option>
        <?php
        $sql = "SELECT * FROM geo1";
        $res = mysqli_query($conn, $sql);
        while ($row = mysqli_fetch_assoc($res)) {
        if ($bul[$row['date']] != true && $row['date'] != 'date') {
        ?>
               <option value="<?php
          echo $row['date'];
          ?>"><?php
          echo $row['date'];
      ?></option>
          <?php
          $bul[$row['date']] = true;
    }
}
?>

    </select>
</div>

<div class="row">
    <label>time: </label>
    <select name="time" id="time-list" class="demoInputBox" onChange="getcountry(this.value);">
        <option value="">Select time</option>
    </select>   
</div>

<div class="row">
    <label>Country: </label>
    <select name="country" id="country-list" class="demoInputBox">
        <option value="">Select country</option>
    </select>   
</div>

<button value="submit" onclick="return showMsg();">Submit</button>
</form>
</div>
</body>
</html>

get_country.php

<?php
    require_once 'dbconnect.php';
    if(!empty($_REQUEST["date_id"])) {
    $query ="SELECT Distinct time FROM geo1 WHERE date =" . "'" . mysqli_escape_string($conn, $_POST["date_id"] ) ."'";
    //echo $query ="SELECT * FROM geo WHERE Region =" . "'" . $_POST["region_id"] ."'";
    $result = mysqli_query($conn, $query);
?>
    <option value="">Select Country</option>
<?php
    while($row2=mysqli_fetch_assoc($result)){
        //var_dump($row2);
        if($bul2[$row2['time']] != true && $row2['time'] != 'time' || 1)        { ?>
            <option value="<?php echo $row2['time']; ?>"><?php echo     $row2['time']; ?>  </option>
 <?php  
         $bul2[$row2['time']] = true;
         }
     }
    }
?>

<?php
    require_once 'dbconnect.php';
    if(!empty($_REQUEST["time_id"])) {
    $query ="SELECT Distinct country FROM geo1 WHERE time =" . "'" . mysqli_escape_string($conn, $_POST["time_id"] ) ."'";
    //echo $query ="SELECT * FROM geo WHERE Region =" . "'" . $_POST["region_id"] ."'";
    $result = mysqli_query($conn, $query);
?>
    <option value="">Select Country</option>
<?php
    while($row2=mysqli_fetch_assoc($result)){
        //var_dump($row2);
        if($bul2[$row2['country']] != true && $row2['country'] != 'country' || 1)        { ?>
            <option value="<?php echo $row2['country']; ?>"><?php echo     $row2['country']; ?>  </option>
 <?php  
         $bul2[$row2['country']] = true;
         }
     }
    }
?>
Answers: