Donna

Journal #4: GetAnnotations($text_id)

I don’t know about the rest of you but this journal entry was brutal! Anyway, my plans for next week are written after the annotations for the function GetAnnotations($text_id).

function GetAnnotations($text_id) {

This line declares the user-defined function called GetAnnotations which contains a variable called $text_id that is passed along to the function to be used by the function later.

$getnotes_query = “SELECT t.id, t.title, nc.ann_line_start, nc.ann_line_end, nc.ann_char_start, nc.ann_char_end

FROM text t, note_comments_on nc

WHERE t.id = nc.note_id AND nc.is_collation = ‘0’ AND nc.annotated_text = ‘”.$text_id.”‘ ORDER BY ann_line_start,ann_char_start;”;

The $getnotes_query is a variable that is used to build the SQL query statement which will be used later on in the function by the mysql_db_query. This SQL statement selects columns from 2 tables called text and note_comments_on with the alias of t and nc respectively. id is a column from the text table as is title. ann_line_start (annotation line start), ann_line_end (annotation line end), ann_char_start (annotation character start) and ann_char_end (annotation character end) are columns from the note_comments_on table. This SQL statement will only select columns where id from the text table is equal to the note id from the note_comments_on table and where is_collation from the note_comments_on table is equal to 0 and where the annotated_text from the note_comments_on is equal to the $text_id variable which was passed to the function earlier. This is sorted first by the ann_line_start column and then by the ann_char_start from the note_comments_on table.

//echo (“GET NOTES FOR THIS TEXT QUERY: “.$getnotes_query.”<br><br>”);

This is a comment used to help debug the SQL statement stored in the $getnotes_query variable. The echo function will print the string GET NOTES FOR THIS TEXT QUERY concatenated with the contents of the variable $getnotes_query and again concatenated with the string <br><br>.

$gotnotes = mysql_db_query(“ecgtextc_damato”,$getnotes_query);

The variable $gotnotes stores the results from the SQL query which is executed by the mysql_db_query function which connects to my database ecgtextc_damato and performs the SQL query stored in the variable $getnotes_query.

if (! $gotnotes) {

This if statement checks whether the variable $gotnotes did not store the results from the SQL query which was executed above. If there was an error and the $gotnotes variable was unable to get the results from the SQL query, the proceeding code will be applied until the closing curly bracket:

$message = ‘Invalid query: ‘ . mysql_error() . “\n”;

The variable $message is being built to be used by the die function (a function the kills the program from further execution). It contains the string Invalid query: concatenated with the results of the function mysql_error which is concatenated again with the \n, a line feed character.

die($message);

This calls the die function with the variable $message because there is an error.

}

This closing curly bracket is the end of the if statement.

$return = array();

The variable $return is built to be returned by the function upon completion. The variable $return is of type array.

$i = 1;

The variable $i is built to be used in the while loop below as a counter and is being initialized to 1.

while ($row = mysql_fetch_array($gotnotes)) {

This while loop executes the function mysql_fetch_array which returns an array of a single row fetched from the SQL statement and stores it in the variable $row.

$return[$i] = $row;

The above line stores the result of a single row fetched from the SQL statement and stores it into the $return variable at position $i.

//echo ($i.”: “.$row[title].”<br>”);

This is a comment that is used to debug what is being stored in the $return variable. The echo function will print the counter stored in the variable $i concatenated with the string : which is concatenated again with the variable $row[title], the column title in the table text, and then concatenated again with the string <br>.

$i++;

The line above increases the counter stored in the variable $i by 1.

}

This closing curly bracket is the end of the while loop.

return $return;

This return exits function and returns the variable $return.

}

This closing curly bracket ends the function GetAnnotation($text_id)

_____________________________________________________________________________________

Since, for whatever reason, I was denied access to the FTP site, I couldn’t upload my work and so I was unable to see what I had accomplished by the end of the week. When I could finally log on, I saw that what I had accomplished, as far as modifying the ‘list of text’ function, was a big, fat nothing! So my plan for this week is to make the necessary revisions so that I don’t get the same error message that I got when I finally was able to upload my work. I will also continue working towards meeting the goal I set out for myself last week (separating the list of annotations from the list of texts) since I have yet to break any ground in that regards. Realistically, I don’t think I will be able to accomplish this goal before the end of this summer semester (3 weeks left!), but I hope to be able to at least take steps in that direction even if they are just failed attempts.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s