simple moteur de recherche
salut,
je suis entrain de developper un petit moteur de recherche
mais j'ai toujours ce probleme qui s'affiche
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-5.3.8.0\www\rentacar\fonction.php on line 19
voila ma fonction.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
|
<?php
mysql_connect("localhost", "root", "") or die("Impossible de se connecter à la base de
données");
mysql_select_db("recherche") or die("base inexistante");
function resultat_recherche($search)
{
$ou="";
$search=preg_split('/[\s]+/',$search);
$total_resultat=count($search);
foreach($search as $key=>$searches)
{
$ou.="mot_clé LIKE '%$searches%'";
if($key!=($total_resultat-1))
{
$ou.=" AND ";
}
}
$query=mysql_query("SELECT* FROM moteurderecherche WHERE $ou");
$rows=mysql_num_rows($query);
if($rows)
{
while($row=mysql_fetch_assoc($query))
{
echo $row['mot_clé']."<br/>".$row['info']."<br/>";
}
}
else
{
echo " pas de résultat pour ".$searches;
}
}
?> |
et mon code search.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
| <?php
mysql_connect("localhost", "root", "") or die("Impossible de se connecter à la base de
données");
mysql_select_db("recherche") or die("base inexistante");
include('fonction.php');
if (isset($_POST['submit']))
{
$search=mysql_real_escape_string(htmlentities(trim($_POST['search'])));
if(empty($search))
{
$error[]="vueillez saisir une recherche";
}
elseif(strlen($search)<2)
{
$error[]="Veuillez insérer une recherche plus détaillé";
}
if (empty($error))
{
resultat_recherche($search);
}
else
{
foreach($error as $errors)
{
echo $errors."<br/>";
}
}
}
?> |
est ce quelqu'un peut m'aider?
merci d'avance :)