Teraz chialbym zrobic tak aby przy wyswietleniu strony pokazywac najpierw wszystkie wyniki z bazy, a potem je zmieniac jak podamy jakis string w input wyszukiwania.
tak wyglad teraz skrypt ktory otwieram:
<script type="text/javascript"> function showResult(str, user) { if (str.length==0) { document.getElementById("all-friends-output").innerHTML=""; document.getElementById("all-friends-output").style.border="1px solid white"; 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("all-friends-output").innerHTML=xmlhttp.responseText; document.getElementById("all-friends-output").style.border="1px solid white"; } } xmlhttp.open("GET","views/galeria/friends/livesearch/allfriends.php?q="+str+"&user="+user,true); xmlhttp.send(); } </script> szukaj znajomych <br /> <input type="text" id="pm-adresat-field" size="30" onkeyup="showResult(this.value, <?echo $_GET['id'];?>);" />
a tak wyglada skrypt php do ktorego przesylam dane:
<?php include("../../../../settings.php"); if (!$connect) { } $db; $search = $_GET['q']; //przesylany string $user_id = $_GET["user"]; //uzytkownik $warunki=" (user_name LIKE '%$wyniki[0]%' || user_surname LIKE '%$wyniki[0]%')"; for ($i=1;$i<count($wyniki);$i++) { $warunki.=" and (user_name LIKE '%$wyniki[$i]%' || user_surname LIKE '%$wyniki[$i]%')"; } $friend_list = mysql_query("SELECT * FROM friends AS a INNER JOIN users AS b LEFT JOIN profile_photos AS c ON b.avatar = c.pp_id AND b.user_id = c.user_id WHERE a.user_id = $user_id AND a.friend_id = b.user_id AND a.accept = 1 AND $warunki"); { } else { { echo .......; } } ?>
odswieze temat gdyz wciaz nie wiem jak to rozwiazac ;(