am asa:
in index.php
Cod: Selectaţi tot
<script type="text/javascript" src="jquery-1.2.1.pack.js"></script>
<script type="text/javascript">
function find(){
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else{
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
document.getElementById('result').innerHTML = XMLHttpRequestObject.responseText ;
}
}
XMLHttpRequestObject.open('GET', 'search.php?query=' document.search.query.value);
XMLHttpRequestObject.send();
}
</script>
Cod: Selectaţi tot
<form id="search" name="search">
Query: <input name="query" onkeyup="find();" placeholder="Scrie cantare" type="text"></form>
<div id="result">te
</div>
Cod: Selectaţi tot
<?php
if (isset($_GET['query'])){
$query = $_GET['query'];
}
//connect to database
if(@mysql_connect('localhost',"root","ialexs")){
if(mysql_select_db('cantari_ppt')){
//if nothing is entered
if(!empty($query)){
//Fetch from database
$sql = "SELECT * FROM cantari_ppt WHERE `denumire` LIKE '$query%' ORDER BY denumire";
$sql_run = mysql_query($sql);
while ($query_row = mysql_fetch_assoc($sql_run)){
echo '<a href="cantare.php?id='.$query_row['id_c'].'">'.$query_row['denumire'].'</a><br>
';
}
}
}
}
?>