crazyglue71 Posted July 8, 2009 Share Posted July 8, 2009 Hi thanks for taking the time to read my question.. I am using one of those ajax autosuggest scripts and i'm unsure on how to get it to connect to the db and pull the results from the db opposed to the $aUsers = array( "Ädams, Egbert", "Altman, Alisha", "Archibald, Janna", ); here is the whole script. <?php $aUsers = array( "Ädams, Egbert", "Altman, Alisha", "Archibald, Janna", ); $input = strtolower( $_GET['input'] ); $len = strlen($input); $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 0; $aResults = array(); $count = 0; if ($len) { for ($i=0;$i<count($aUsers);$i++) { // had to use utf_decode, here // not necessary if the results are coming from mysql // if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input) { $count++; $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]) } if ($limit && $count==$limit) break; } } header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 if (isset($_REQUEST['json'])) { header("Content-Type: application/json"); echo "{\"results\": ["; $arr = array(); for ($i=0;$i<count($aResults);$i++) { $arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}"; } echo implode(", ", $arr); echo "]}"; } else { header("Content-Type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>"; for ($i=0;$i<count($aResults);$i++) { echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>"; } echo "</results>"; } ?> thank you very much for the help. Link to comment https://forums.phpfreaks.com/topic/165175-mysql-connect-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.