Id like any words in my dictionary database to match any possible matching word in $stringoftext and if there is a match, display the word and definition after connecting to the database. Let's say for example my dictionary database contains three matching words Abnormal, Abortion, and Abuse which just so happen to be in my $stringoftext variable.
<?
$stringoftext = "Abnormal Abortion Abuse Elephants Dinosours Boogieman)";
$db = mysql_pconnect("localhost", "", "");
mysql_select_db("journals",$db);
$query=mysql_query("SELECT * FROM dictionary") or die(mysql_error());
while($row = mysql_fetch_array($query)) {
$matches = mysql_num_fields($query);
preg_match_all("/\S+/", $stringoftext, $matches);
for($i=0;$i < count($matches); $i++) {
$k = mysql_field_name($query,$i);
$$k = $row[$k];
}
print "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=19%>$word</td><td width=81%>$definition</td></tr></table>";
}
?>
The following is how I'd like the output to appear after the above query, but at the moment just get blank output. :
Abnormal - Definition here.
Abortion - Definition here.
Abuse - Definition here.
I have a feeling I'm doing something wrong around the 'while' command but not sure.