I am getting the error message

Notice: Uninitialized string offset: 7 in
c:\inetpub\wwwroot\webpage10\example\search\dsp_se arch.php on line 61

What it should be doing is grabbing each word specified in the search box
and compare this to the database keywords for each row in the column
keywords. Therefore, I could have lets say 400 records. When a user does a
search, it will search in the column keywords and run through this matching
every keyword and displaying the matching result. Each record keyword
column can have multiple keywords that are delimited with a comma. What is
happening is that this working just fine but it for some reason it is trying
to match the array positions up and when they don't match it gives the error
when it should really grab the the entered words for the search, remove the
unneccesary words and chars if any, compare each searched word to the whole
keywords column, and display the information it protains too and s on. Here
is the code to give an idea of what I'm doing.

//qry that returns all matches
$results = mssql_query ("SELECT img_id, img_location, img_name,
img_keywords, category_id FROM images ORDER BY img_id ASC");

echo ("<TABLE border=0 cellpadding=2 cellspacing=2 width=100%>");
echo ("<tr bgcolor=\"#CCCC99\"><td>Thumbnail</td><td>Category
Name</td><td>File Name <span class=\"smalltext\">Search took
<strong>2.66</strong> sec.</span></td></tr>");

$search_string = trim($_POST["search"]);
$search_string = strip_tags($search_string);
$search_string = strtolower($search_string);
$search_string = str_replace("\n", "", $search_string);
$search_string = c_strip_chars($search_string); //strip chars from input
$search_string = str_replace(",", "", $search_string);
$search_string = explode(" ", $search_string);
$search_string = i_strip_words($search_string); //strip specific words from
input search

$j = 0;
$count = 0;
$img_width = 25;
$img_height = 25;

foreach($search_string as $word) {

//pull in DB stuff and do the same to it as above
$imgName = mssql_result($results, $j,"img_name");
$imgKeywords = mssql_result($results, $j,"img_keywords");

$imgKeywords = strip_tags($imgKeywords);
$imgKeywords = strtolower($imgKeywords);
$imgKeywords = str_replace("\n", "", $imgKeywords);
$imgKeywords = c_strip_chars($imgKeywords); //strip chars from keywords if

$imgKeywords = explode(",", $imgKeywords);

for ($i = 0; $i < mssql_num_rows($results); $i++){

foreach($imgKeywords as $keywords){

if ($word == ""){
echo ("<tr><td colspan=6>No results were found. Please search
"<tr><td colspan=6><p>&nbsp;</p></td><?/tr>".
"<tr><td colspan=6><p>&nbsp;</p></td><?/tr>".
"<tr><td colspan=6><p>&nbsp;</p></td><?/tr>".
"<tr><td colspan=6><p>&nbsp;</p></td><?/tr>");
elseif ($word[$j] == $keywords[$i]) { // line 61

$image_loc = mssql_result($results,$i,"img_location");
$image_name = mssql_result($results,$i,"img_name");
$imageID = mssql_result($results,$i,"img_id");
$imageCategory = mssql_result($results,$i,"category_id");

$categoryName = mssql_query("SELECT cat_name FROM category WHERE cat_id
= '$imageCategory'");
$categoryName = mssql_result($categoryName,0,"cat_name");

echo ("<tr>".
"<td><img src='$image_loc' border=2 width=$img_width height=$img_height
align=left alt='$image_name'></td>".

echo ("</TABLE>");

Anyone see why it is doing whats its doing? Do have the order missed up or
should I use an alternative to foreach?