suche.js
suche.php
index.php container:
PHP Code:
function searchFor(suchbegriff){
var xmlHttp = null;
// Mozilla, Opera, Safari sowie Internet Explorer 7
if (typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
if (!xmlHttp) {
// Internet Explorer 6 und älter
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xmlHttp = null;
}
}
}
if (xmlHttp) {
var url = "suche.php";
var params = "suchbegriff="+suchbegriff;
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
document.getElementById("changeContent").innerHTML = xmlHttp.responseText;
}
};
xmlHttp.send(params);
}
}
PHP Code:
<?php
$cn = mysqli_connect("localhost","","","");
if ($_POST["suchbegriff"]){
$sql= mysqli_query($cn,"SELECT * FROM Table WHERE name LIKE ('%".mysqli_real_escape_string($cn,utf8_decode($_POST["suchbegriff"]))."%')");
echo "Sie Suchten nach: ".$_POST["suchbegriff"]."<br/><br/>";
while($asatz = mysqli_fetch_assoc($sql)){
$name = strtolower($asatz['name']);
$pos = strpos($name,$_POST['suchbegriff']);
if($pos === 0){
echo "
<div style='display:block;float:left;text-align:center;'>
<img src='".$asatz["bild"].".jpg' width='160px' height='180px' class='img-thumbnail'style='display:block;height:180px;width:160px;'></img>
<button class='btn btn-default' name='aSuche' value='".$asatz["id"]."'style='display:block;min-width: 160px;'>$asatz[name]</button>
</div>";
}
else{
$pos = strpos($asatz['name'],$_POST['suchbegriff']);
if($pos === 0){
echo "
<div style='display:block;float:left;text-align:center;'>
<img src='".$asatz["bild"].".jpg' width='160px' height='180px' class='img-thumbnail'style='display:block;height:180px;width:160px;'></img>
<button class='btn btn-default' name='aSuche' value='".$asatz["id"]."'style='display:block;min-width: 160px;'>$asatz[name]</button>
</div>";
}
}
}
}
?>
PHP Code:
<div id='changeContent'style ='width:100%; height: 100%;'>
</div>
PHP Code:
$("button[name=aSuche]").click(function(){
var id = $( this ).val()
$("#changeContent").load("search.php?id="+id);
});






oder 