ho provato inserendo la funzione strtoupper ma non funziona
cosa sbaglio?
Codice PHP:
<?php
$part = $_GET['part'];
$part=strtoupper($part);
$link = mysql_connect('localhost', 'db', 'passw');
mysql_query("SET NAMES 'utf8';");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db("db")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$result = mysql_query("SELECT nome FROM persone WHERE nome LIKE '$part%' LIMIT 10");
while ($row = mysql_fetch_assoc($result)) {
$colors[]=$row['nome'];
}
mysql_free_result($result);
mysql_close($link);
$length = strlen($part);
// check the parameter
if(isset($_GET['part']) and $_GET['part'] != ” and $length > 1)
{
// initialize the results array
$results = array();
// search colors
foreach($colors as $color)
{
// if it starts with 'part' add to results
if( strpos($color, $_GET['part']) === 0 ){
$results[] = $color;
}
}
// return the array as json with PHP 5.2
echo json_encode($results);
}
?>
la pagina dove c'è il campo text input è
codice:
<script src="jquery.js" type="text/javascript"></script>
<script src="dimensions.js" type="text/javascript"></script>
<script src="autocomplete.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
setAutoComplete("searchField", "results", "autocomplete.php?part=");
});
</script>
</head>
<body>
<h1>Ajax autocomplete using PHP & MySQL</h1>
<p id="auto">
<label>Colors: </label>
<input id="searchField" name="searchField" type="text" />
</p>
</body>