autocomplete search-box to echo another box with data from database

autocomplete search-box to echo another box with data from database



I have created an auto-complete search-box, where by once I write a word, words are listed down, and I choose what I want, and it displays the choice in my input text-box. What I want is that once I search for the item, the data from the database should appear in another box. Here is my code..




$(document).ready(function()
$("#search-box").keyup(function()
$.ajax(
type: "POST",
url: "readDesease.php",
data:'keyword='+$(this).val(),
beforeSend: function()
$("#search-box").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
,
success: function(data)
$("#suggesstion-box").show();
$("#suggesstion-box").html(data);
$("#search-box").css("background","#FFF");

);
);
);

function selectDiagnosis(val)
$("#search-box").val(val);
$("#suggesstion-box").hide();


<tr>
<td>Diagnosis-1</td>
<td>
<input type="text" id="search-box" name="search-box" placeholder="Desease Name" required="required" />
<div id="suggesstion-box"></div>

<?php
$conn = new mysqli("localhost", "root", "", "coding") or die(mysqli_error());
$sa=$_POST['search-box'];
$query = $conn->query("SELECT * FROM Diagnosis_code WHERE col2 = $sa ") or die(mysqli_error());
$fetch = $query->fetch_array();
?>

<td>
<input type="text" id="search-block" name="search-block" placeholder="block Name" required="required" value=" <?php echo $fetch ?> " />
</td>
</tr>

<!--this is readeDesease.php-->
<?php
require_once("dbcontroller.php");
$db_handle = new DBController();
if(!empty($_POST["keyword"]))
$query ="SELECT * FROM diagnosis_code WHERE col2 like '%" . $_POST["keyword"] . "%' OR col1 like '%" . $_POST["keyword"] . "%' ORDER BY col2 LIMIT 0,50";
$result = $db_handle->runQuery($query);
if(!empty($result))
?>
<ul id="diagnosis-list">
<?php
foreach($result as $diagnosis)
?>
<li onClick="selectDiagnosis('<?php echo $diagnosis["col1"]; ?>');"><?php echo $diagnosis["col2"]."<strong>".$diagnosis["col1"]."</strong>"; ?></li>
<?php ?>
</ul>
<?php ?>





Could you specify your problem? What is working, and what isn't? Does the auto complete functionality work? Are you getting any sql errors?
– Martin
Aug 27 at 7:25






the auto-complete work but what i need is when i select the item, then the data could appear into two input-box where one represent col1 and another col2
– gerald
Aug 27 at 10:46









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

How do I collapse sections of code in Visual Studio Code for Windows?