I thought there may have been a way to do this with MySQL but I cant find it.
1. Create an array of all the names
Code:
$nameArray = array();
$result = mysql_query("select distinct(lower(name)) from names");
while(list($name) = mysql_fetch_row($result)){
$nameArray[] = $name;
}
2. Run through getting counts. I dont know what you want to do with the data, so I will put it into a simple array so you can do what you want.
Code:
$final = array();
$result = mysql_query("select id, lower(sentence) from sentences");
while(list($id, $sent) = mysql_fetch_row($result)){
$count=0;
foreach($nameArray as $n){
$count += substr_count($sent, $n);
}
$final[$id] = $count;
}