I tried to search forum within this tags but cannot receive any results. So there is my problem:
I want to make live search which shows me results in specified div. I made this script which is located at the bottom of index page:
$(function(){
$("#q").keyup(function(){
var q = $(this).val();
$.get("base.php?q="+q, function(data){
if(q){
$(".results").show();
$(".results").html(data);
} else{
$(".results").hide();
$(".results").html("");
}
});
});
});
I have put two titles in db: 'league of legends' and 'league of heroes'. I want to fetch titles based on query from search input. Last time i tried to this, php file gave me everything from db and insert it at the top of file instead of selected in js div (.results).
there is php file:
<?php
//connection stuff
$c = mysql_connect("", "", "");
$db = mysql_select_db("", $c);
//page number
if($_GET["page"]){
$pagenum = $_GET["page"];
} else{
$pagenum = 1;
}
$rowsperpage = 2;
$offset = ($pagenum - 1) * $rowsperpage;
//keywords
$t = trim(eregi_replace(" +", " ", $_GET["q"]));
$x = explode(" ", $t);
foreach($x as $z){
$w++;
if($w==1){
$u .= "channel LIKE '%$z%'";
} else{
$u .= "OR channel LIKE '%$z%'";
}
}
//page of results
$q = mysql_query("SELECT * FROM channels WHERE $u ORDER BY id DESC LIMIT $offset, $rowsperpage");
$page_nums = mysql_num_rows($q);
$total_q = mysql_query("SELECT * FROM channels WHERE $u");
$total_nums = mysql_num_rows($total_q);
$total_pages = ceil($total_nums/$rowsperpage);
if($total_nums){
if($pagenum<1||$pagenum>$total_pages){
header("Location: base.php?q=$t");
}
while($r=mysql_fetch_array($q)){
$channel = $r["channel"];
$id = $r["id"];
echo '<div class="result"><a class="link" href="?channel='.$id.'">'.$channel.'</a></div>';
}
$range = 2;
if($pagenum>1){
$page = $pagenum - 1;
$first = '<a class="page" id="1">First</a> ';
$prev = '<a class="page" id="'.$page.'">Prev</a> ';
}
if($pagenum<$total_pages){
$page = $pagenum + 1;
$next = '<a class="page" id="'.$page.'">Next</a> ';
$last = '<a class="page" id="'.$total_pages.'">Last</a> ';
}
for($page=($pagenum-$range); $page<=($pagenum+$range); $page++){
if($page>=1&&$page<=$total_pages){
if($total_pages>1){
if($page==$pagenum){
$nav .= '<span class="pagenum">'.$page.'</span> ';
} else{
$nav .= '<a class="page" id="'.$page.'">'.$page.'</a> ';
}
}
}
}
echo $first . $prev . $nav . $next . $last;
} else{
echo 'No results for <b>"'.$t.'"</b>';
}
?>
I want this shadow box to appear if results were found, ofc with results in it (this box has 'results' class).

New Topic/Question
Reply


MultiQuote



|