Mysql
 sql >> Database >  >> RDS >> Mysql

In caso di modifica dei valori a discesa query risp. tabelle - con php, mysql, ajax, jquery

utente ajax onchange select box passa il valore di select

HTML

 <select name="sometest" onchange="javascript:call_ajax_fun(this.value);">
      <option value="1"> A </option>
      <option value="2"> B </option>
      <option value="3"> C </option>
      <option value="4"> D </option>
      <option value="5"> E </option>
    </select>

Funzione JS Ajax

function call_ajax_fun(str)
{

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {

            var result = xmlhttp.responseText;
            if(xmlhttp.responseText!='')
            {
                document.getElementById('your_result_div_id').innerHTML =result ;
                            // put your result in your div 
            }   
        }
    }



    var url="get_result.php?pas_val="str;

    xmlhttp.open("GET",url,true);

    xmlhttp.send();
}

e il file dei risultati di acquisizione sarà il seguente

get_result.php

<?php
if(isset($_REQUEST['pas_val']))
{
   $pas_val = $_REQUEST['pas_val'];
   if($pas_val<5)
   {
     $tbl = "table_1";
   }
   else
  {
     $tbl = "table_2";
  }


// your table is in $tbl variable
//   your your table here in your code


}
else
{
  exit;
}
?>