Autor | Zpráva | ||
---|---|---|---|
Hezyk Profil * |
#1 · Zasláno: 2. 9. 2010, 17:50:17
Jak se to dá upravit, aby to místo prvních písmen napovídalo podle
title like '%neco%' <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $aUsers = array(); while($rows=mysql_fetch_array($result)) $aUsers[]=$rows["title"]; $aInfo = array( "Bedfordshire", "Buckinghamshire", "Cambridgeshire", "Nottinghamshire" ); $input = strtolower( $_GET['input'] ); $len = strlen($input); $aResults = array(); 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) $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) ); //if (stripos(utf8_decode($aUsers[$i]), $input) !== false) // $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) ); } } 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; charset=windows-1250"); 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; charset=windows-1250"); echo "<?xml version=\"1.0\" encoding=\"windows-1250\" ?><results>"; for ($i=0;$i<count($aResults);$i++) { echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>"; } echo "</results>"; } ?> |
||
Alphard Profil |
#2 · Zasláno: 2. 9. 2010, 22:18:23
Hezyk:
Tenhle kód je tak otřesný, že bych ho ani neupravoval, ale zkusil se maximálně inspirovat pro nový… Do sql dotazu na 11. (za předpokladu, že ten vybírá ta data) dodejte where title like '%neco%' (nezapomeňte ošetřit sql injection).
Pak dlouhou část nahradit ošetřením (pokud je nutné, nevím, kde data berete), použít funkci json_encode() a na závěr by byl snad použitelný ten export do XML, i když by šel také udělat lépe. |
||
Časová prodleva: 14 let
|
0