I have solved the issue myself by trying to fix things with experimentation.
My first problem was that the code I used to remove duplicate entries from the search array was basically looping twice. So, I edited the source to keep it from looping twice.
do
{
$adid_array[] = $row['page_id'];
}
while($row = mysql_fetch_array($numresults));
$tmparr = array_unique($adid_array);
$i = 0;
foreach ($tmparr as $newarr_v)
{
$newarr[$i] = $newarr_v;
$i++;
}
And then I use newarr to execute the search query (with foreach).
Secondly, because this is my first experience with building a search page, I used stock code and didn't notice that it was erroneously building a query for each keyword entered, instead of a query that incorporates all keywords (if multiple). So I removed
foreach ($search_array as $search_keyword)
, and wrote a little code to separate each keyword with AND.
$var = addslashes(htmlspecialchars($_GET['q'])) ;
// trim whitespace from the stored variable
$trimmed = trim($var);
// separate key-phrases into keywords
$trimmed_array = explode(" ",$trimmed);
// count keywords
$trimm_total = count($trimmed_array);
$i = 0;
$searchstring = '';
// looping to get the search string
foreach ($trimmed_array as $trimm)
{
if ($i != 0 and $i != $wordcount)
{
$searchstring .= " AND ";
}
$searchstring .= "text LIKE '%$trimm%' OR page_title LIKE '%$trimm%' OR author LIKE '%$trimm%'";
// incrementing the value
$i = $i + 1;
}
And now it finally works.