hello I get this error after looking for a word in my search script

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

here is the code:
PHP Code:
$query "SELECT * FROM search HAVING MATCH (keywords) AGAINST ('$search') GROUP BY head2";
$result mysql_query($query);
while(
$a_row mysql_fetch_array($result)) {
echo 
"<tr><td background=images/newpage2/bg.gif width=5 height=19></td><td width=384>";
echo 
$a_row['head2'];
echo 
"</td><td background=images/newpage2/bg2.gif width=5 height=19></td></tr>";
$cat $a_row['head2'];
$query2 "SELECT * FROM search WHERE head2 = '$cat'";
$result2 mysql_query($query2);
while(
$b_row mysql_fetch_array($result2)) {
echo 
"<tr><td background=images/newpage2/bg.gif width=5 height=19></td><td width=384>";
echo 
"<a href="http://www.whatever.com/$b_row[head].php?id=$b_row[sid]">$b_row[display]</a>";
echo "</td><td background=images/newpage2/bg2.gif width=5 height=19></td></tr>";
}