Joseph Witchard
08-21-2009, 08:40 PM
$query1 = "SELECT COUNT(*) FROM posts WHERE post_body LIKE '%$search_term%'";
if ($result1 = $conn->query($query1))
{
// make sure something was returned
$stored = $result1->store_result;
$num_rows = $stored->num_rows;
if ($num_rows <= 0)
{
echo "<p class='warning'>Your search didn't match anything in our database.</p>";
}
So, I'm building a search form for my site. The problem is the form always tells me nothing is returned when I search for something that I know is in the database. What I find odd, though, is if I remove the code that checks to make sure something is returned, the same test search fetches everything from the database perfectly. What gives?
if ($result1 = $conn->query($query1))
{
// make sure something was returned
$stored = $result1->store_result;
$num_rows = $stored->num_rows;
if ($num_rows <= 0)
{
echo "<p class='warning'>Your search didn't match anything in our database.</p>";
}
So, I'm building a search form for my site. The problem is the form always tells me nothing is returned when I search for something that I know is in the database. What I find odd, though, is if I remove the code that checks to make sure something is returned, the same test search fetches everything from the database perfectly. What gives?