Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anyone help me with my code because im just new in web developing...i want to do to my program is if i search a batchcode to a search textbox it will automatically filter and shows in their corresponding texboxes.

in my current code its not working...i need your help guys...please

example: i want my output to be like this.

http://s38.photobucket.com/user/eloginko/media/aa_zpsd1e1659b.png.html[^]



html code:

XML
<form method="post">
Search batchcode: <input type="text" name="code" id="query" /><input type="submit" value="Go" name="search" /><br />
<table>
<tr>
<td>
ID: <br />
<input id="result" type="text" name="id1" value="<?php if(empty($id[0])){$id[0] = array(NULL);}else{echo $id[0];} ?>" readonly /> <br />
<input id="result" type="text" name="id2" value="<?php if(empty($id[1])){$id[1] = array(NULL);}else{echo $id[1];} ?>" readonly /> <br />
</td>
<td>
Name: <br />
<input id="result" type="text" name="name1" value="<?php if(empty($name[0])){$name[0] = array(NULL);}else{echo $name[0];} ?>" readonly /> <br />
<input id="result" type="text" name="name2" value="<?php if(empty($name[1])){$name[1] = array(NULL);}else{echo $name[1];} ?>" readonly /> <br />
</td>
<td>
Score 1: <br />
<input id="result" type="text" name="optA1" value="<?php if(empty($score1[0])){$score1[0] = array(NULL);}else{echo $score1[0];} ?>" onChange="optTotal1()" /> <br />
<input id="result" type="text" name="optA2" value="<?php if(empty($score1[1])){$score1[1] = array(NULL);}else{echo $score1[1];} ?>" onChange="optTotal2()" /> <br />
</td>
<td>
Score 2: <br />
<input id="result" type="text" name="optB1" value="<?php if(empty($score2[0])){$score2[0] = array(NULL);}else{echo $score2[0];} ?>" onChange="optTotal1()" /> <br />
<input id="result" type="text" name="optB2" value="<?php if(empty($score2[1])){$score2[1] = array(NULL);}else{echo $score2[1];} ?>" onChange="optTotal2()" /> <br />
</td>
<td>
Other Qualification: <br />
<input id="result" type="text" name="other_qual1" value="<?php if(empty($other_qual[0])){$other_qual[0] = array(NULL);}else{echo $other_qual[0];} ?>" readonly /> <br />
<input id="result" type="text" name="other_qual2" value="<?php if(empty($other_qual[1])){$other_qual[1] = array(NULL);}else{echo $other_qual[1];} ?>" readonly /> <br />
</td>
<td>
Interview: <br />
<input id="result" type="text" name="interview1" value="<?php if(empty($interview[0])){$interview[0] = array(NULL);}else{echo $interview[0];} ?>" readonly /> <br />
<input id="result" type="text" name="interview2" value="<?php if(empty($interview[1])){$interview[1] = array(NULL);}else{echo $interview[1];} ?>" readonly /> <br />
</td>
<td>
Total: <br />
<input id="result" type="text" name="total1" value="<?php if(empty($total[0])){$total[0] = array(NULL);}else{echo $total[0];} ?>" readonly onKeyUp="optTotal1()" /> <br />
<input id="result" type="text" name="total2" value="<?php if(empty($total[1])){$total[1] = array(NULL);}else{echo $total[1];} ?>" readonly onKeyUp="optTotal2()" /> <br />
</td>
</tr>
</table>
<input type="submit" value="update" name="update" />
</form>




script for search function:

XML
<script type="text/javascript">
$(document).ready(function(){

    $("#query").autocomplete({
        source : 'search.php',
        select : function(event,ui){
            $("#result").html(ui.item.value);
        }
    });

});
</script>



search.php page code:


PHP
<?php

$q = $_GET['term'];

mysql_connect("localhost","root","");
mysql_select_db("test");
$batchcode = $_POST['code'];
$query = mysql_query("SELECT DISTINCT batchcode FROM score WHERE batchcode LIKE '$q%'");

$data = array();
while($row = mysql_fetch_array($query)){
$data[]=array('value'=>$row['batchcode']);
        $id[] = $rows['id'];
        $name[] = $rows['name'];
        $score1[] = $rows['score1'];
        $score2[] = $rows['score2'];
        $other_qual[] = $rows['score3'];
        $interview[] = $rows['score4'];
        $total[] = $rows['total'];
}
echo json_encode($data);


?>
Posted
Comments
Killzone DeathMan 7-Feb-14 6:17am    
Hello, I think there is a syntax error in your autocomplete code, "source : 'search.php'"
it must be an array "source : {"label":"test"}", look here:

http://www.jqueryautocomplete.com/jquery-autocomplete-json-example.html

I think you must do a POST to the search.php file, and then pass the result to the "source" of your autocomplete code.
And there are unused code in the search.php file..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900