Connection to database error
Posted: Mon Feb 07, 2011 11:03 am
For some reason, the search is not pulling records from my database.
I know I am searching for results that are present, but keep showing 'No results found.'
Please help!!!
I know I am searching for results that are present, but keep showing 'No results found.'
Code: Select all
<?php
//get data
$button = $_GET['submit'];
$search = $_GET['search'];
if (!$button)
echo "You didn't submit a keyword.";
else
{
if (strlen($search)<=2)
echo "search term too short.";
else
{
echo "You searched for $search <hr size='1'>";
//connect to database and search
mysql_connect("localhost", "root", "");
mysql_select_db ("a2288820_data");
//explode our search term
$search_exploded = explode("", $search);
// doughhhhh
foreach($search_exploded as $search_each)
//construct query
$x++;
if ($x==1)
$construct .="keyword1 LIKE '%$search_each%'";
else
$construct .="OR keyword1 LIKE '%$search_each%'";
//echo out construct
$construct = "SELECT * FROM publications WHERE $construct";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
if ($foundnum==0)
echo "No results found.";
else
{
echo "$foundnum results found!<p>";
while ($runrows = mysql_fetch_assoc())
{
//get data
$author = $runrows['author1'];
echo "
<b> $author</b>
";
}
}
}
}
?>