Hi,
I am having problems returning values from a select statement. When I query directly in the databse, I get back the information I am looking for. I use an includes file for the database connection and my page shows that the connection was successful. Here is my code:
<?php
$search = $_GET['searchFor'];
$words = explode(" ", $search);
$phrase = implode("%' AND articlename LIKE '%", $words);
$sql ="SELECT * FROM articles WHERE articlename LIKE '%phrase%'";
$result =$conn->query($sql) or die('Sorry, could not get any articles at this time');
$row =($result->fetch_all()) or die('No records found');
$numRows =$result->num_rows;
If($numRows==0)
{
echo "<h2>Sorry, no articles were found with '$search' in them.</h2>";
}
else
{
While($row=$result->fetch_assoc())
{
$articleid = $row['articleid'];
$title = $row['articlename'];
$shortdesc = $row['shortdesc'];
echo "<h2>Search Results</h2><br><br>\n";
echo "<a href=\"index.php?content=showarticle&id=$articleid\">$title</a><br>\n";
echo "$shortdesc<br><br>\n";
}
}
?>
The search term is coming from a search form in the navigation. I have used "echo" statements to check and make sure that the sesrch word is coming through to tghe page containing the above code. I have tried mysqli_error() statements in several places and don't see where the problem is. When I try the search the message that comes back is "No records found" Does not makee sense because I know it is there, can find it, and even have the same syntax as the SELECT statement I use when I ask for the php code. Going crazy trying to sort this out. Any suggestions, help etc are greatly appreciated. Thank youi.