Jump to content

show data in search without using submit button


eloginko

Recommended Posts

How to filter and show data in search without using submit button..because thats the only function i need to finish my code..can anyone help me? I dont want to use submit button cause it refreshes the page...I have the code for search already I need a function that after I search the data will show in the textboxes without using submit button.

 

php code:

 

<?php

if($_GET){

include('include/connect.php');

$batchcode = $_GET['code'];

$sql = mysql_query("SELECT aic,batchcode,address,name FROM tb_app WHERE batchcode = '".$batchcode."' ");

if($sql) {

while($rows = mysql_fetch_array($sql)){

$aic[] = $rows['aic'];

$name[] = $rows['name'];

$address[] = $rows['address'];

}

}

}else{

$aic = array(NULL,NULL,NULL,NULL);

$name = array(NULL,NULL,NULL,NULL);

$address = array(NULL,NULL,NULL,NULL);

}

?>

 

html code:

 

<html>

<head>

<title>test</title>

</head>

<body>

<form action="" method="get">

Search Batchcode:<input type="text" name="code" id="query" /><br />

<table>

<tr>

<td>

aic: <br />

<input type="text" name="optA1" value="<?php if(empty($aic[0])){$aic[0] = array(NULL);}else{echo $aic[0];} ?>" /> <br />

<input type="text" name="optA2" value="<?php if(empty($aic[1])){$aic[1] = array(NULL);}else{echo $aic[1];} ?>" /> <br />

<input type="text" name="optA3" value="<?php if(empty($aic[2])){$aic[2] = array(NULL);}else{echo $aic[2];} ?>" /> <br />

<input type="text" name="optA4" value="<?php if(empty($aic[3])){$aic[3] = array(NULL);}else{echo $aic[3];} ?>" /> <br />

</td>

<td>

Name List: <br />

<input type="text" name="optB1" value="<?php if(empty($name[0])){$name[0] = array(NULL);}else{echo $name[0];} ?>" /> <br />

<input type="text" name="optB2" value="<?php if(empty($name[1])){$name[1] = array(NULL);}else{echo $name[1];} ?>" /> <br />

<input type="text" name="optB3" value="<?php if(empty($name[2])){$name[2] = array(NULL);}else{echo $name[2];} ?>" /> <br />

<input type="text" name="optB4" value="<?php if(empty($name[3])){$name[3] = array(NULL);}else{echo $name[3];} ?>" /> <br />

</td>

<td>

Address: <br />

<input type="text" name="optC1" value="<?php if(empty($address[0])){$address[0] = array(NULL);}else{echo $address[0];} ?>" /> <br />

<input type="text" name="optC2" value="<?php if(empty($address[1])){$address[1] = array(NULL);}else{echo $address[1];} ?>" /> <br />

<input type="text" name="optC3" value="<?php if(empty($address[2])){$address[2] = array(NULL);}else{echo $address[2];} ?>" /> <br />

<input type="text" name="optC4" value="<?php if(empty($address[3])){$address[3] = array(NULL);}else{echo $address[3];} ?>" /> <br />

</td>

</form>

</body>

</html>

 

script code:

 

<!--search function code-->

<script type="text/javascript">

$(document).ready(function(){

 

$("#query").autocomplete({

source : 'search.php',

select : function(event,ui){

$("#query").html(ui.item.value);

}

});

 

});

</script>

 

search.php page code:

 

<?php

 

$q = $_GET['term'];

 

mysql_connect("localhost","root","");

mysql_select_db("test");

$query = mysql_query("SELECT DISTINCT batchcode FROM tb_app WHERE batchcode LIKE '$q%'");

 

$data = array();

while($row = mysql_fetch_array($query)){

$data[]=array('value'=>$row['batchcode']);

}

echo json_encode($data);

?>

Archived

This topic is now archived and is closed to further replies.

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