dimanche 27 décembre 2015

How can I return the ID based from its first name and last name in autocomplete in PHP?

Here is the index.php code (i got this online, credits to the owner):

 <HTML>
 <HEAD>
  <TITLE> Ajax php Auto Suggest </TITLE>

  <link href="css/style.css" rel="stylesheet" type="text/css">

 <SCRIPT LANGUAGE="JavaScript" src="js/jquery.js"></SCRIPT>
 <SCRIPT LANGUAGE="JavaScript" src="js/script.js"></SCRIPT>
 </HEAD>
 <BODY>
 <center>

   <div class="main">
      <div class=""><a href="http://ift.tt/1ShxGVq">scriptime</a></span></div>
         <div id="holder"> 
         Enter Keyword : <input type="text" id="keyword" tabindex="0"><img src="images/loading.gif" id="loading">
         </div>
         <div id="ajax_response"></div>

   </div>
 </center>

 </BODY>
</HTML>

And here is the .php code (the config is working just fine).

<?php
include("config.php");
$keyword = $_POST['data'];
$sql = "select idPerson, firstName, middleName, lastName from ".$db_table." where ".$db_column." like '".$keyword."%'";
//$sql = "select name from ".$db_table."";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result))
{
    echo '<ul class="list">';
    while($row = mysql_fetch_array($result))
    {
        $str = ($row['idPerson']);
        $str1 = ($row['firstName']);
        $str2 = ($row['middleName']);
        $str3 = ($row['lastName']);
        //$start = strpos($str,$keyword); 
        //$end   = similar_text($str,$keyword); 
        //$last = substr($str,$end,strlen($str));
        //$first = substr($str,$start,$end);

        $final = '-'.$str.' '.$str2;

        echo '<li><a href=\'javascript:void(0);\'>'.$str.' - '.$str1.' '.$str2.' '.$str3.'</a></li>';
    }
    echo "</ul>";
}
else
    echo 0;?>      

THIS IS THE OUTPUT: If I click the value, I want that the textbox would return its ID only. How can I do that? I really need help. I still suck at this.




Aucun commentaire:

Enregistrer un commentaire