Page 1 of 1

Connection to database error

Posted: Mon Feb 07, 2011 11:03 am
by peachiness
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.'

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>
";


}

}


}
}

?>
Please help!!!

Re: Connection to database error

Posted: Mon Feb 07, 2011 12:30 pm
by AbraCadaver

Code: Select all

echo $construct;

Re: Connection to database error

Posted: Mon Feb 07, 2011 2:05 pm
by peachiness
AbraCadaver wrote:

Code: Select all

echo $construct;
What do you mean by that?