Saving NULL values Empty text boxes on a form return an empty string. Storing NULL in the database takes up less room Modify the bindValue statement to check for the empty string. $statement->bindValue(':pName', $pName==''?null:$pName); pName is the parameter/field name No processing seems to be necessary when displaying NULL values on a form Retrieving Data From the Result Set print_r the result set Queries typically return one of four things: Use a foreach loop to a bunch of records display all the fields and a single record their values from the first a single value record in the result set as Returned by statistical functions (count, max, unordered list items. etc) A row count Note the odd structure of Returned by insert, update and delete queries, the array designating how many records were effected The query results are returned to the calling routine (probably the controller) by one of the query functions in the model library. These processing techniques described below are used in the views (GUI) to display the contents of the result set. Returning and processing lots of records Returning $results = $statement->fetchAll(PDO::FETCH_ASSOC); $statement->closeCursor(); return $results; Processing Tip: Before doing too much processing use to display the contents of the print_r $results array. The variable is an array of records. $result Each record is an array of key/value pairs (field names and field values) Use a foreach loop to walk through the array records <?php foreach($employees as $emp) : ?> display record data here <?php endforeach; ?>
Saving NULL values Empty text boxes on a form return an empty string. Storing NULL in the database takes up less room Modify the bindValue statement to check for the empty string. $statement->bindValue(':pName', $pName==''?null:$pName); pName is the parameter/field name No processing seems to be necessary when displaying NULL values on a form Retrieving Data From the Result Set Queries typically return one of four things: a bunch of records a single record a single value Returned by statistical functions (count, max, etc) A row count Returned by insert, update and delete queries, designating how many records were effected The query results are returned to the calling routine (probably the controller) by one of the query functions in the model library. These processing techniques described below are used in the views (GUI) to display the contents of the result set. print_r the result set Use a foreach loop to display all the fields and their values from the first record in the result set as unordered list items. Note the odd structure of the array Returning and processing lots of records Returning $results = $statement->fetchAll(PDO::FETCH_ASSOC); $statement->closeCursor(); return $results; Processing Tip: Before doing too much processing use print_r to display the contents of the $results array. The $result variable is an array of records. Each record is an array of key/value pairs (field names and field values) Use a foreach loop to walk through the array records <?php foreach($employees as $emp) : ?> display record data here <?php endforeach; ?>