J'ai parcouru un peu le forum mais n'ai pas trouvé ce que je cherchais, je me permets donc de demander de l'aide à la communauté PHP, en espérant qu'une bonne âme voudra bien m'aider...
J'ai fait avec un ami un moteur de recherche bibliographique dans une base de données. J'ai un problème avec l'une des options de mon moteur de recherche.
J'aimerais rechercher une information dans deux champs différents d'une même table. Voici le code qui pose problème:
Code : Tout sélectionner
if ($choix == "auteur")
{
$sql = "SELECT DISTINCT * FROM ma_table WHERE auteur LIKE '%$motsclef%' OR auteursimple LIKE '%$motsclefs%'";
if ($methode == "OR" && $nbmots > 1)
{
$sql = "SELECT DISTINCT * FROM ma_table WHERE auteur LIKE '%$mots[0]%' OR auteursimple LIKE '%$mots[0]%'";
for ($i=1; $i<$nbmots; $i++)
{
$sql .=" OR auteur LIKE '%$mots[$i]%' OR auteursimple LIKE '%$mots[$i]%'";
}
}
}Le même type de recherche sur d'autres champs fonctionnent sans problème. Exemple
Code : Tout sélectionner
if ($choix == "titre")
{
$sql = "SELECT * FROM ma_table WHERE titre LIKE '%$motsclef%' OR intitre LIKE '%$motsclef%'";
if ($methode == "OR" && $nbmots > 1)
{
$sql = "SELECT * FROM ma_table WHERE titre LIKE '%$mots[0]%' OR intitre LIKE '%$mots[0]%'";
for ($i=1; $i<$nbmots; $i++)
{
$sql .=" or titre like '%$mots[$i]%' or intitre like '%$mots[$i]%'";
}
}
}Ma table:
Code : Tout sélectionner
CREATE TABLE `ma_table` (
`id` mediumint(9) NOT NULL auto_increment,
`anneebull` text NOT NULL,
`numbull` text NOT NULL,
`auteur` text NOT NULL,
`auteursimple` text NOT NULL,
`annee` text NOT NULL,
`titre` text NOT NULL,
`inauteurs` text NOT NULL,
`intitre` text NOT NULL,
`collection` text NOT NULL,
`ville` text NOT NULL,
`pages` text NOT NULL,
`cr` text NOT NULL,
`resume` text NOT NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1351 ;
Merci d'avance aux bonnes âmes qui passeraient par ici
Philam