Je voudrais effectuer des recherches sur plusieurs tables, qui, plus ou moins, comportent les meme champs, mais se pose 2 problemes:
1- Soit que le mot recherche ne se trouve pas par la query, alors qu'il existe dans la table,
2- Soit il me donne des resultats doublons.
Voila les 2 tables:
Code : Tout sélectionner
CREATE TABLE IF NOT EXISTS `recherche1` (
`id` int(2) NOT NULL auto_increment,
`titre` varchar(20) collate latin1_general_ci NOT NULL,
`texte` longtext collate latin1_general_ci NOT NULL,
`url` varchar(30) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ;
--
-- Dumping data for table `recherche1`
--
INSERT INTO `recherche1` (`id`, `titre`, `texte`, `url`) VALUES
(1, 'titre 1 de recherche', 'c''est la premiere fois que je code du php', 'code.php'),
(2, 'titre 2 recherche 1', 'j''adore coder du php', 'code1.php'),
(3, 'fonction php', 'fonction', 'code.php');
CREATE TABLE IF NOT EXISTS `recherche2` (
`id` int(2) NOT NULL auto_increment,
`titre` varchar(20) collate latin1_general_ci NOT NULL,
`texte` longtext collate latin1_general_ci NOT NULL,
`url` varchar(30) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ;
--
-- Dumping data for table `recherche2`
--
INSERT INTO `recherche2` (`id`, `titre`, `texte`, `url`) VALUES
(1, 'titre 1 de recherche', 'c''est la premiere fois que je code du php2', 'code2.php'),
(2, 'titre 2 recherche2', 'j''adore coder du php2', 'code3.php');
// connexion et tout le blabla
$word = 'fonction'; // avec fonction, il me donne des resultats errones, et avec php il me donne de bons resultats
$query = "select * from recherche1, recherche2 where recherche1.texte LIKE '%$word%' OR recherche2.texte LIKE '%$word%'";
echo $query.'<br>';
$result = mysql_query ($query) or die (mysql_error());
$total = mysql_num_rows($result);
echo $total.' resultats<br>';
if ($total) {
while ($row = mysql_fetch_array($result)) {
$texte = $row['texte'];
$titre = $row['titre'];
$url = $row['url'];
$id = $row['id'];
echo 'id: '.$id.' '.$titre;
echo '<br>'.$texte;
echo '<br>'.$url.'<hr>';
}
}
else
{
echo 'Aucun resultat';
}
?>