I am working on this project where I have this MySQL database with a table named "speechesLCMcoded" with thousands of lines of parsed text. I have four columns that are "key", "parsed", "weight" and "count".
The text in the column "parsed" looks like this:
{N}table{/N}{V}play{/V}{A}big{/A}
I have another table that is named "concreteness" that has two columns, In the column "word" I have a list of words and in the column "score" I have each word's concreteness score. For example it would look like this
Word Score
table 5
play 3
big 2
I am working on a php script that will calculate for each line of my table "speechesLCMcoded" the total cumulated score of each word and the total number of scored words.
In my example, the result would look like this:
Key parsed weight count
1 {N}table{/N}{V}play{/V}{A}big{/A} 10 3
I have written a part of the script but I am stuck because of my limited experience with php. I am confused by the fact that there are two "while" loops in my script
How would you advise me to do?
<?php
//Include functions
include "functions.php";
ini_set('max_execution_time', 90000);
echo 'Time Limit = ' . ini_get('max_execution_time');
//Conecting the database
if (!$conn) {
die('Not connected : ' . mysql_error());}
// make LCM the current db
mysql_select_db('senate');
$data = mysql_query("SELECT `key`, `tagged` FROM speecheLCMcoded")
or die(mysql_error());
// puts the "data" info into the $info array
while($info = mysql_fetch_array( $data) ){
$key=$info['key'];
$tagged=$info['tagged'];
// Print out the contents of the entry
Print "<b>Key:</b> ".$info['key'] . " <br>";
// Select Word List and their weights
$dataweights = mysql_query("SELECT `word`, `weight` FROM concreteness")
or die(mysql_error());
// puts the "data" info into the $infoweights array
while($infoweights = mysql_fetch_array( $infoweights) ){
$word=$info['word'];
$score=$info['score'];
// Calulate number of adjectives
ob_start(); //Start output buffer
print substr_count($tagged,"{");
$adjectives = ob_get_contents(); //Grab output
ob_end_clean(); //Discard output buffer
// Calulate number of coded items
//Saving number of coded words
$sql = "UPDATE speechestest SET adjectives='$adjectives', verbs='$verbs', nouns='$nouns' WHERE `key`='$key';" ;
$retval = mysql_query( $sql, $conn );
if(! $retval )
{die('Could not update data: ' . mysql_error());}
echo "Updated data successfully
";
}
?>