par
Fredy07 » 27 juin 2009, 02:46
voila le code complet:
<?php
//
$word = 'php';
//echo $word.'<br>';
$query = "select * from recherche1, recherche2 where recherche1.texte1 LIKE '%$word%' OR recherche2.texte2 LIKE '%$word%'";
echo $query.'<br>';
$result = mysql_query ($query) or die (mysql_error());
$total = mysql_num_rows($result);
echo $total.'<br>';
if ($total) {
while ($row = mysql_fetch_array($result)) {
$texte1 = $row['texte1'];
$texte2 = $row['texte2'];
$url1 = $row['url1'];
$url2 = $row['url2'];
$titre1 = $row['titre1'];
$titre2 = $row['titre2'];
echo 'voila le texte1'.$texte1.' et voila son url: '.$url1.' et le titre '.$titre1.'<br>';
echo 'voila le texte1'.$texte2.' et voila son url: '.$url2.' et le titre '.$titre2.'<br>';
}
//echo 'voila url' .$url.'<br>';
//echo 'voila le texte'.$text.'<br>';
}
else
{
echo 'aucun resultat';
}
//
?>
et le code des 2 tables recherche1 et recherche2:
--
-- Table structure for table `recherche1`
--
CREATE TABLE IF NOT EXISTS `recherche1` (
`id1` int(2) NOT NULL auto_increment,
`titre1` varchar(20) collate latin1_general_ci NOT NULL,
`texte1` longtext collate latin1_general_ci NOT NULL,
`url1` varchar(30) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id1`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ;
--
-- Dumping data for table `recherche1`
--
INSERT INTO `recherche1` (`id1`, `titre1`, `texte1`, `url1`) 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');
-- --------------------------------------------------------
--
-- Table structure for table `recherche2`
--
CREATE TABLE IF NOT EXISTS `recherche2` (
`id2` int(2) NOT NULL auto_increment,
`titre2` varchar(20) collate latin1_general_ci NOT NULL,
`texte2` longtext collate latin1_general_ci NOT NULL,
`url2` varchar(30) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id2`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ;
--
-- Dumping data for table `recherche2`
--
INSERT INTO `recherche2` (`id2`, `titre2`, `texte2`, `url2`) 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');
et les resultats sont comme suite:
select * from recherche1, recherche2 where recherche1.texte1 LIKE '%php%' OR recherche2.texte2 LIKE '%php%'
4
voila le texte1c'est la premiere fois que je code du php et voila son url: code.php et le titre titre 1 de recherche
voila le texte1c'est la premiere fois que je code du php2 et voila son url: code2.php et le titre titre 1 de recherche
voila le texte1j'adore coder du php et voila son url: code1.php et le titre titre 2 recherche 1
voila le texte1c'est la premiere fois que je code du php2 et voila son url: code2.php et le titre titre 1 de recherche
voila le texte1c'est la premiere fois que je code du php et voila son url: code.php et le titre titre 1 de recherche
voila le texte1j'adore coder du php2 et voila son url: code3.php et le titre titre 2 recherche2
voila le texte1j'adore coder du php et voila son url: code1.php et le titre titre 2 recherche 1
voila le texte1j'adore coder du php2 et voila son url: code3.php et le titre titre 2 recherche2
voila le code complet:
[php]
<?php
//
$word = 'php';
//echo $word.'<br>';
$query = "select * from recherche1, recherche2 where recherche1.texte1 LIKE '%$word%' OR recherche2.texte2 LIKE '%$word%'";
echo $query.'<br>';
$result = mysql_query ($query) or die (mysql_error());
$total = mysql_num_rows($result);
echo $total.'<br>';
if ($total) {
while ($row = mysql_fetch_array($result)) {
$texte1 = $row['texte1'];
$texte2 = $row['texte2'];
$url1 = $row['url1'];
$url2 = $row['url2'];
$titre1 = $row['titre1'];
$titre2 = $row['titre2'];
echo 'voila le texte1'.$texte1.' et voila son url: '.$url1.' et le titre '.$titre1.'<br>';
echo 'voila le texte1'.$texte2.' et voila son url: '.$url2.' et le titre '.$titre2.'<br>';
}
//echo 'voila url' .$url.'<br>';
//echo 'voila le texte'.$text.'<br>';
}
else
{
echo 'aucun resultat';
}
//
?>
[/php]
et le code des 2 tables recherche1 et recherche2:
[php]--
-- Table structure for table `recherche1`
--
CREATE TABLE IF NOT EXISTS `recherche1` (
`id1` int(2) NOT NULL auto_increment,
`titre1` varchar(20) collate latin1_general_ci NOT NULL,
`texte1` longtext collate latin1_general_ci NOT NULL,
`url1` varchar(30) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id1`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ;
--
-- Dumping data for table `recherche1`
--
INSERT INTO `recherche1` (`id1`, `titre1`, `texte1`, `url1`) 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');
-- --------------------------------------------------------
--
-- Table structure for table `recherche2`
--
CREATE TABLE IF NOT EXISTS `recherche2` (
`id2` int(2) NOT NULL auto_increment,
`titre2` varchar(20) collate latin1_general_ci NOT NULL,
`texte2` longtext collate latin1_general_ci NOT NULL,
`url2` varchar(30) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id2`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ;
--
-- Dumping data for table `recherche2`
--
INSERT INTO `recherche2` (`id2`, `titre2`, `texte2`, `url2`) 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');[/php]
et les resultats sont comme suite:
[php]select * from recherche1, recherche2 where recherche1.texte1 LIKE '%php%' OR recherche2.texte2 LIKE '%php%'
4
voila le texte1c'est la premiere fois que je code du php et voila son url: code.php et le titre titre 1 de recherche
voila le texte1c'est la premiere fois que je code du php2 et voila son url: code2.php et le titre titre 1 de recherche
voila le texte1j'adore coder du php et voila son url: code1.php et le titre titre 2 recherche 1
voila le texte1c'est la premiere fois que je code du php2 et voila son url: code2.php et le titre titre 1 de recherche
voila le texte1c'est la premiere fois que je code du php et voila son url: code.php et le titre titre 1 de recherche
voila le texte1j'adore coder du php2 et voila son url: code3.php et le titre titre 2 recherche2
voila le texte1j'adore coder du php et voila son url: code1.php et le titre titre 2 recherche 1
voila le texte1j'adore coder du php2 et voila son url: code3.php et le titre titre 2 recherche2[/php]