Hi, i am trying to get this script to work correctly, but am not having much luck.I have been trying to change this tutorial to integrate with my database.
The problem i have is when it creates a link to the result it is only creating a link for the first item only. Any help would be appreciated.Also i have nearly 27,000 entries in the table bb1_dad_roll would this cause a problem for the webhost if i used a script like this online?
problem.jpg
This is my gethint.php file:
This is my HTML file (seems to work ok):Code:<?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("roh", $con); $result = mysql_query("SELECT * FROM bb1_dad_roll"); while($row = mysql_fetch_array($result)) { $id = $row['roll_id']; $surname = $row['roll_surname']; $forename = $row['roll_forename']; $b[] = $id; $a[] = $surname; $c[] = $forename; } mysql_close($con); //get the q parameter from URL $q=$_GET["q"]; //lookup all hints from array if length of q>0 if (strlen($q) > 0) { $hint=""; for($i=0; $i<count($a); $i++) { if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q)))) { if ($hint=="") { $hint="<br /><a href=\"test.php?id=$b[$i]\">".$a[$i]." ".$b[$i]."</a><br />"; } else { $hint = "<a href=\"test.php?id=$b[$i]\">$hint $a[$i] , $c[$i] $b[$i]</a><br />"; } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint == "") { $response="no suggestion"; } else { $response=$hint; } //output the response echo $response; ?>
Code:<html> <head> <script type="text/javascript"> function showHint(str) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","gethint.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <p><b>Start typing a name in the input field below:</b></p> <form> First name: <input type="text" onkeyup="showHint(this.value)" size="20" /> </form> <p>Suggestions: <span id="txtHint"></span></p> </body> </html>


I have been trying to
Also i have nearly 27,000 entries in the table bb1_dad_roll would this cause a problem for the webhost if i used a script like this online?
Reply With Quote
Bookmarks