Journal 4: AddLinesToText($text_id)

(My goal this week is to finish up last week’s activity of alphabetization now that I have at last downloaded the proper files with FTP, thanks to Kalervo’s help. Also, I hope to return to this annotation after reading others and making the necessary changes to my preliminary understanding of the function!)

The function AddLinesToText performs a task when a user of the ecgtext site clicks on the tab “Add Lines” at the top of a selected text. The site refreshes and displays a new page, which shows the text lines entered so far followed by blank, numbered text lines where the user can input new information. (example:

Please note that I often referred to the Nixon book,, and when completing this activity.

My annotations are in italics below the lines of the function they describe.

function AddLinesToText($text_id) {

This user-defined, not pre-defined, function is declared and opened with the { symbol.

                $gottext = GetThisText($text_id);

                $line_number_last = 0;

                $line_last = ”;

The variables are assigned their values. However, I don’t understand why they are given values of zero and a quotation mark.

                foreach ($gottext as $row) {

A foreach…as loop is started to go through all items in the array, placing them in the variable $row, and ending when all values have been used. I think this loop’s purpose is to display the rows of the text selected by the user.

                                $return .= $row[clause_number];

The return statement makes the function stop its execution and returns a value. Here, the return statement uses the period to append another string to it. So, $row becomes a subsection of $return.

                                if (! $formheader) {

                                                $formheader = “Add Lines to Text “.$text_id.”: “.$row[title];


The foreach loop has two if statements. If the condition is true, the program takes the action defined within curly braces.

This first if statement has an exclamation mark before it, a “logical NOT” operator, meaning that it will return the opposite of the value. Does anyone know why that would be necessary here?

The variable $formheader is assigned a literal string. When a user clicks on “Add Lines” on a text, the page refreshes and the header is displayed. The header contains the words in the string “Add Lines to Text,” followed by the text number and title assigned by the user. String concatenation is used again here to combine this information into one phrase.

                                if ($row[clause_number] > $line_number_last) {

                                                $line_number_last = $row[clause_number];

                                                $line_last = $row[strng];



This second if statement uses a comparison operator between the $row and $line_number_last variables. Therefore, if the clause number is greater than the last line number, the next two lines are executed. My understanding is that this statement displays the row number and characters of the last row of the previously entered text.

                $line_number_start = $line_number_last + 1;

This variable uses an arithmetic operator, the plus sign, to display the next line number. For instance, if the user previously entered 5 lines of text, when the new page to add lines is displayed, the first empty row would have the number 6.               

                $return = “<form method=post action=v_newtext.php>

                                <table cellspacing=4 cellpadding=0 width=100%>

                                <tr><td colspan=2>”.$formheader.”</td></tr>


This return statement displays HTML, which is the information between < >. The form tag tells how to send the form data, which in this case is the post method. I believe that when the form is submitted, it will be sent to newtext.php. The tr tag defines a row and the td tag defines a cell. This HTML information formats the header of the text.

                if ($line_number_last > 0) {

                                $return .= “<tr><td width=20 align=left>”





This if statement is used in cases when data was previously entered into a row in the text because its condition is that the line number is greater than zero. I think that the HTML information displays the row number that was assigned above.

                $form = “<input type=hidden name=text_id value=”.$text_id.”>”;

This HTML input type defines a hidden field, which is the name of the text.

                for ($n = 1; $n<= 15; $n++) {

A for loop sets up the variable and then tests for conditions and modifies variables. This loop works for a line numbered 1, line numbers of less than or equal to 15, and increments of the value.

                                $current_line = $n + $line_number_last;

I believe this variable sets each line number as one number higher than the previous line.

                                $form .= “<tr><td>


                                                <input type=text size=80 maxlength=300 name=clause_number”.$current_line.”></td></tr>”;


In HTML, a class points to a change in a style sheet. The choice of type as text specifies that an input field will be displayed and the maximum length of characters is 300.

                $form .= “<tr><td></td><td>

                                <input type=hidden name=formtype value=addlines>

                                <input type=submit value=’Add Lines’></td></tr>”;

This HTML code has the type “submit” (as opposed to “text” above), which creates a submit button to send the data entered to the server. This button appears at the bottom of the web page after the 15 rows.

// 1. if a text, find out how many lines in text already

// 2. if not, and if an annotation, create new text

// 3. insert lines into DB

                $return .= $form.”</table></form>”;

                return $return;


This statement returns to the calling code and the HTML closes the table and form.


Leave a Reply

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

You are commenting using your 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