Hey Guys,
I m new here. I need a help

I am working with a s/w where I need to fetch data from database onchange event.
actually scene is the user will select one option (ie. name of company) from the dropdown box. According to that value the s/w should run query and fetch that company's data from MySQL db and the fetched data will be displayed on its related textboxes. This all should happen onchange event itself

here is my code:

<form action='form1.php' method='post'>
<select name="<?="company".$a?>" id="<?="company".$a?>" onchange="search1()">
<option value=""></option>
 <?
$comp_list = mysql_query("SELECT name FROM comp_name");
while($comp= mysql_fetch_array($comp_list) )
{                   
?>
<option value="<?=$comp[name]?>"><?=$comp[name]?></option>";
<?
}
$sel = $_REQUEST["company".$a];
$chk1 = mysql_query("SELECT date_modified, current_rate from price_tab where company = '$sel' and date_modified = (SELECT max(date_modified) from price_tab where model_no = '$model_no')");
$fet1 = mysql_fetch_array($chk1);
?>
 </select>
 <input type="text" size="15" name="<?="pre_date".$a?>" id="<?="pre_date".$a?>" value="<?=$fet1[date_modified]?>" readonly>
 <input type="text" size="15" name="<?="pre_rate".$a?>" id="<?="pre_rate".$a?>" value="<?=$fet1[current_rate]?>" readonly>
 <input type="text" size="15" name="<?="cur_rate".$a?>" id="<?="cur_rate".$a?>">
 <?
 $i++;  
 }
?>

<script language="JavaScript1.2" type="text/javascript">
function search1(val)
{
    document.forms[0].action="search.php"   
    document.forms[0].submit();
}
</script>

there are 2 ways,
1) conventional way,
on changing selection, you can submit page to server,
on server php source will fetch record by parameter passed
display record on page

2) jquery/ajax
You need to learn jquery/ajax
on changing selection, you can pass value to server without submitting whole page
then server will send response(you have to write request handler and u need to send response code)
you can display server response on the page

Thanks for ur advice... but satill I cant make out the things... :(

its working with ajax

you have to write AJAX function on onchange event to display dynamic data from database.
Please check following example:

<script>
function showDetails(id)
{

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)
    {
    document.getElementById("details").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","test.php?q="+id,true);
xmlhttp.send();
}
</script>

<select name="users" onchange="showDetails(this.value)">
<option value="">Select:</option>
<option value="1">1</option>
<option value="2">2</option>

</select>

<div id='details'></div>

Amazing.. thanks for your code.. It really helped.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.