PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$query = "SELECT * FROM articleTable WHERE (articleTitle LIKE '$srch1' OR articleText LIKE '$srch1') AND (dateOfArticle BETWEEN '$fromDate' AND '$untilDate')";
This code is working, but I would like to add the possibility to search "$srch2" and "$srch3" in both columns "articleTitle" and "articleText" but without the obligation that they be filled in.
I've tried the following, but it doesn't seem to work:
$query = "SELECT * FROM articleTable WHERE ((articleTitle LIKE '$srch1' OR '$srch2' OR '$srch3') OR (articleText LIKE '$srch1' OR '$srch2' OR '$srch3')) AND (dateOfArticle BETWEEN '$fromDate' AND '$untilDate')";
SELECT *
FROM articleTable
WHERE
(articleTitle LIKE '$srch1' OR articleTitle LIKE '$srch2' OR articleTitle LIKE '$src3'
OR articleText LIKE '$srch1' OR articleText LIKE '$srch2' OR articleText LIKE '$src3')
AND (dateOfArticle BETWEEN '$fromDate' AND '$untilDate')
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
For some reason that's not working for me. Here's the full code to my 2 programs... maybe that helps to figure it out? Using the SQL query you gave me (included in the posted code) it returns all the results the database holds unless I have 2 search criteria, in which case it works. But if I enter 3 keywords it doesn't. Not sure why.
[u][b]buildArticleList.php[/b][/u]
<html>
<head>
<title>Baso de datos de Rodolfo</title>
<link href="styles/styles.css" rel="stylesheet" type="text/css">
<?
include("includes/misc.inc");
include("includes/menuBar.php");
include("includes/connection.inc");
if (!"")
{
$srch1 = "%".$search1."%";
$srch2 = "%".$search2."%";
$srch3 = "%".$search3."%";
$fromDate = "$year1-$month1-$day1";
$untilDate = "$year2-$month2-$day2";
$query = "SELECT *
FROM articleTable
WHERE
(articleTitle LIKE '$srch1' OR articleTitle LIKE '$srch2' OR articleTitle LIKE '$src3'
OR articleText LIKE '$srch1' OR articleText LIKE '$srch2' OR articleText LIKE '$src3')
AND (dateOfArticle BETWEEN '$fromDate' AND '$untilDate')";
$result = mysql_query($query);}
if ($result)
{
echo "Here are the results:";
$table_content = "";
$table_content .= "<table border='1'>";
while ($row = mysql_fetch_array($result)) {
$table_content .= "<tr>
<td>".$row['articleIDNumber']."</td>
<td>".$row['dateOfArticle']."</td>
<td>".$row['categories']."</td>
<td>".$row['articleTitle']."</td>
<td>".$row['articleText']."</td>
</td>
</tr>";
}
$table_content .= "</table>";
echo $table_content;
}
else {
echo '<div align="center"><strong>No elegiste nada para buscar!!!</strong></div><br>';
}
mysql_close();
?>
</body>
</html>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
$query = "SELECT *
FROM articleTable
WHERE ((articleTitle LIKE \"%$search1%\"
OR articleText LIKE \"%$search1%\"
OR articleTitle LIKE \"%$search2%\"
OR articleText LIKE \"%$search2%\"
OR articleTitle LIKE \"%$search3%\"
OR articleText LIKE \"%$search3%\"))
AND dateOfArticle
BETWEEN '$fromDate' AND '$untilDate'";