Autocomplete Search With Link

293 Views Asked by At

So I'm Creating A School Management System And On The View Students Page I'm Wanting A Autocomplete Search System That Returns A Link Which Will Link To Another Page

But It Needs To Look Through The Students Table To Get The id For The Page As Its viewrecord.php?id= then the students id, and also the name of the student for autocomplete system, how can this be done with mysqli?

I previously tried, this is it without sql selection, it didn't work with links:

<input type="text" name="srch" id="srch" list="datalist1">
<datalist id="datalist1">
  <option value="Canada">
  <option value="China">
  <option value="Mexico">
  <option value="United Kingdom">
  <option value="United States of America">
  <option value="Uruguay">
</datalist>

something like that ^^^

The students table is below
id bigint(20), Auto Incrememnt And Primary
first_name varchar(255)
last_name varchar(255)
room varchar(255)
dob varchar(255)
And Finally 
email varchar(255)
1

There are 1 best solutions below

0
On BEST ANSWER

You can have a workaround like this

Step 1 :

Get the input in the textbox and have a jquery which triggers in keyup function

$(".search").keyup(function() 
{
//your ajax call here
}

Step 2.

Inside the function have an ajax call to another file which queries for your input

$.ajax({
type: "POST",
url: "search.php",
data: dataString,
cache: false,
success: function(html)
{
//your action
}
});

Step 3 :

In the success, you can replace the result inside the div near your search

$("#result").html(html).show();

Step 4 :

Inside the search.php you can get the input and query for the table and for result, and construct a hyper link which suits your need.

i.e., user.php?id=xyz

So that you can navigate to that page easily

Which would have the code something like

<a href="user.php?id=<?php echo $row['id']?>"><span class="name"><?php echo $username; ?></span>
</a>

Here is the source code and here is the demo i have created a demo which suits your needs just for you ;)