Mysqli multi_query Search of 2 Tables Not showing Results
I'm up to my neck trying to figure out why my query isn't working. This is
what my search.php page results in. I am able to _GET the search term
perfectly but can't display the results.
Not sure if the issue is the fetch_array_assoc or what! Here's my code.
Any help with this would be appreciated. Not 100% sure if my syntax is
correct.
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$button = $_GET ['submit'];
$search = $_GET ['query'];
if(strlen($search)<=1)
echo "Search term too short";
else{
echo "You searched for <b>$search</b> <hr size='1'></br>";
$con= new mysqli("localhost","user","pass","db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$search_exploded = explode (" ", $search);
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$query = "Keyword_ID LIKE '%$search_each%' or
Keyword_Name LIKE '%$search_each%' ";
else
$query .= "OR Keyword_ID LIKE '%$search_each%' or
Keyword_Name LIKE '%$search_each%' ";
}
$construct = mysqli_query($con,"SELECT * FROM profileTable WHERE
$query");
$construct = mysqli_query($con,"SELECT * FROM addKeywordTable
(Keyword_Name) WHERE $query");
$constructs = mysqli_multi_query($construct);
if(mysqli_multi_query($construct))
{
$numrows = mysqli_num_rows($query);
if ($numrows > 0) {
while ($row = mysqli_fetch_assoc($constructs)) {
$key = $row['Keyword_Name'];
$keyID = $row['keyID'];
$fname = $row['FirName'];
$lname = $row['LaName'];
$mname = $row['MName'];
$suffix = $row['Suffix'];
$title = $row['Title'];
$dept = $row['Dept'];
$phone1 = $row['PH1'];
$phone2 = $row['PH2'];
$email = $row['Email'];
$photo = $row['Photo'];
$bio = $row['BioLK'];
$tags = $row['Tags'];
echo '<h2>$fname $lname</h2>';
echo $key;
echo $title;
echo $dept;
}
}
else
echo "Results found: \"<b>$x</b>\"";
}
}
mysqli_close();
?>
I am trying to search two different tables. addKeywordTable and
profileTable. Profile table has all of the profile info for a user. The
addKeywordTable stores the keywords/tag names 'Keyword_Name'.
I attempted to create a mysqli_multi_query but its not working at all.
No comments:
Post a Comment