Améliorer un moteur de recherche php ajax
Salut à tous :-)
ben voilà, je suis vraiment débutant en ajax, je suis passionné par les moteurs de recherche, j'ai pu trouver sur la toile un moteur à peu près valable mais il me liste une partie de la base au démarrage (genre livre d'or) je voudrais supprimer cela.
et autre chose, l'auteur de ce script utilise beaucoup de sous fichiers, alors est-ce possible de se débarrasser de certains inutiles ou les condencer (meric.
je poste les fichiers et bon courage!
testpage.php (le fichier index)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MOTEUR PHP AJAX</title>
<!--on charge la fonction javascript pagination.js-->
<script language="JavaScript" src="pagination.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<?php
error_reporting(E_ALL^E_NOTICE);
include('pagination_class.php');
//connexion
@mysql_connect('localhost', 'root', '') or die(mysql_error());
@mysql_select_db('booraqdb');
$qry = "SELECT * FROM moteur";
$mots = "";
if($_REQUEST['mots']!=""){
$mots = $_REQUEST['mots'];
$qry .=" where description like '%$mots%'";
}
//for pagination...$starting
$starting=0;
$recpage = 6;//number of records per page
$obj = new pagination_class($qry,$starting,$recpage);
$result = $obj->result;
?>
<!--FORMULAIRE-->
<FORM name="form1" action="testpage.php" method="POST">
<table border="1" align="center" width="40%">
<tr>
<TD colspan="2">
Search <input type="text" name="mots" value="<?php echo $mots; ?>">
<input type="submit" name="valider" value="Search">
</TD>
</tr>
<tr><TD colspan="2">
<!--on place ici le résultat-->
<div id="page_contents">
<table border="1" align="center" width="100%">
<tr><TD>Sl no</TD><TD>Name</TD><TD>Description</TD></tr>
<?php
if(@mysql_num_rows($result)!=0){
$counter = $starting + 1;
while($data = @mysql_fetch_array($result)) {
?>
<tr>
<TD><?php echo $counter; ?></TD>
<TD><?php echo $data['nom']; ?></TD>
<TD><?php echo $data['description']; ?></TD>
</tr><?php
$counter ++;
}
?>
<tr><TD colspan="3"><?php echo $obj->anchors; ?></TD colspan="3"></tr>
<tr><TD colspan="3"><?php echo $obj->total; ?></TD></tr>
<?php
}else{
?>
<tr><TD align="center" colspan="2">No Data Found</TD></tr>
<?php
}
function sanitize_string($str) {
if (get_magic_quotes_gpc()) {
$sanitize = @mysql_real_escape_string(stripslashes($str));
} else {
$sanitize = @mysql_real_escape_string($str);
}
return $sanitize;
}
?>
</TD></tr>
</table>
</div>
</TD></tr>
</table></FORM>
</body>
</html> |
pagination.js
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
var xmlHttp
function pagination(page)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="test_sub.php";
url = url+"?starting="+page;
url = url+"&mots="+document.form1.mots.value;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("page_contents").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
} |
pagination_class.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
<?php
/*
Developed by Reneesh T.K
reneeshtk@gmail.com
You can use it with out any worries...It is free for you..It will display the out put like:
First | Previous | 3 | 4 | 5 | 6 | 7| 8 | 9 | 10 | Next | Last
Page : 7 Of 10 . Total Records Found: 20
*/
Class Pagination_class{
var $result;
var $anchors;
var $total;
function Pagination_class($qry,$starting,$recpage)
{
$rst = @mysql_query($qry) or die(mysql_error());
$numrows = @mysql_num_rows($rst);
$qry .= " limit $starting, $recpage";
$this->result = @mysql_query($qry) or die(mysql_error());
$next = $starting+$recpage;
$var = ((intval($numrows/$recpage))-1)*$recpage;
$page_showing = intval($starting/$recpage)+1;
$total_page = ceil($numrows/$recpage);
if($numrows % $recpage != 0){
$last = ((intval($numrows/$recpage)))*$recpage;
}else{
$last = ((intval($numrows/$recpage))-1)*$recpage;
}
$previous = $starting-$recpage;
$anc = "<ul id='pagination-flickr'>";
if($previous < 0){
$anc .= "<li class='previous-off'>First</li>";
$anc .= "<li class='previous-off'>Previous</li>";
}else{
$anc .= "<li class='next'><a href='javascript:pagination(0);'>First </a></li>";
$anc .= "<li class='next'><a href='javascript:pagination($previous);'>Previous </a></li>";
}
################If you dont want the numbers just comment this block###############
$norepeat = 4;//no of pages showing in the left and right side of the current page in the anchors
$j = 1;
$anch = "";
for($i=$page_showing; $i>1; $i--){
$fpreviousPage = $i-1;
$page = ceil($fpreviousPage*$recpage)-$recpage;
$anch = "<li><a href='javascript:pagination($page);'>$fpreviousPage </a></li>".$anch;
if($j == $norepeat) break;
$j++;
}
$anc .= $anch;
$anc .= "<li class='active'>".$page_showing."</li>";
$j = 1;
for($i=$page_showing; $i<$total_page; $i++){
$fnextPage = $i+1;
$page = ceil($fnextPage*$recpage)-$recpage;
//ici on utilise la fonction javascript pagination.js
$anc .= "<li><a href='javascript:pagination($page);'>$fnextPage</a></li>";
if($j==$norepeat) break;
$j++;
}
############################################################
if($next >= $numrows){
$anc .= "<li class='previous-off'>Next</li>";
$anc .= "<li class='previous-off'>Last</li>";
}else{
$anc .= "<li class='next'><a href='javascript:pagination($next);'>Next </a></li>";
$anc .= "<li class='next'><a href='javascript:pagination($last);'>Last</a></li>";
}
$anc .= "</ul>";
$this->anchors = $anc;
$this->total = "Page : $page_showing <i> Of </i> $total_page . Total Records Found: $numrows";
}
}
?> |
test_sub.php (affichage en cas de requête limite, ce fichier répète un peu le fichier du départ testpage.php)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MOTEUR PHP AJAX</title>
<!--on charge la fonction javascript pagination.js-->
<link rel="stylesheet" type="text/css" href="style.css" />
<?php
include('pagination_class.php');
@mysql_connect('localhost', 'root', '') or die(mysql_error());
@mysql_select_db('booraqdb');
$qry = "SELECT * FROM moteur";
if($_REQUEST['mots']!=""){
$mots = $_REQUEST['mots'];
$qry .=" where nom like '%$mots%'";
}
//for pagination
if(isset($_GET['starting'])&& !isset($_REQUEST['submit'])){
$starting=$_GET['starting'];
}
else{
$starting=0;
}
$recpage = 6;//number of records per page
$obj = new pagination_class($qry,$starting,$recpage);
$result = $obj->result;
?>
<table border="1" align="center" width="100%">
<tr><TD>Sl no</TD><TD>Name</TD><TD>Description</TD></tr>
<?php
if(@mysql_num_rows($result)!=0){
$counter = $starting + 1;
while($data = @mysql_fetch_array($result)) {?>
<tr>
<TD><?php echo $counter; ?></TD>
<TD><?php echo $data['nom']; ?></TD>
<TD><?php echo $data['description']; ?></TD>
</tr><?php
$counter ++;
} ?>
<tr><TD colspan="3"><?php echo $obj->anchors; ?></TD colspan="3"><tr>
<tr><TD colspan="3"><?php echo $obj->total; ?></TD></tr>
<?php } else{ ?>
<tr><TD align="center" colspan="2">No Data Found</TD></tr>
<?php } ?>
</TD></tr>
</table>
</body>
</html> |
alors je remercie toute personne qui voudrais bien m'aider...
NB: par contre en php et mysql je m'y connais un peu.