First time poster, hopefully not the last. Trying to build a "swear-o-meter"
to read data from my forum and just display a total of words used. Now, the
code I have semi-works but misses something out of the loop (output at the bottom of this post) - and it's going
to be an obvious answer to almost anyone here (fingers crossed).
Code is as follows (I've missed out the sql connect stuff and replaced
certain search criteria):
$con = mysql_connect($DB_SERVER, $DB_USER, $DB_PASS);
mysql_select_db($DB_NAME);
// The bit that does the swear count for the Swear-O-Meter
$ultimatetotal = 0;
// The wordlist array is a lot longer than that and a great deal more "blue"
$wordlist = array("bottom", "arse", "pillock");
$counter = count ($wordlist);
echo ("Swear word number to be counted = ".$counter."<br><br>");
for ($index = 0 ; $index < $counter; $index++) {
$swear[$index] = mysql_query("SELECT wordid FROM word WHERE title REGEXP
'$wordlist[$index]'");
$swearout = mysql_fetch_array($swear[$index]);
$swearcount[$index] = mysql_query("SELECT count(*) FROM searchindex WHERE
wordid = '$swearout[$index]'",$con);
$sweartotal = mysql_fetch_array($swearcount[$index]);
$ultimatetotal = $ultimatetotal + $sweartotal[$index];
echo ("Current word: ".$wordlist[$index]."<br>");
echo ("How many words have we found?: ".$sweartotal[$index]."<br>");
echo ("Total words so far: ".$ultimatetotal."<br>");
}
Now, the output I get is weird and seems to hinge on the fact that the loop
is not doing something it should be.
Swear word number to be counted = 3
Current word: bottom
How many words have we found?: 3
Total words so far: 3
Current word: arse
How many words have we found?:
Total words so far: 3
Current word: pillock
How many words have we found?:
Total words so far: 3