ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions
3 marks · PHP database functions
Explain the use made of the mysqli_num_rows() function at line 40. Re‑write the following lines to show the code needed to produce the HTML table: Line 44 Line 46. A query is executed and the pupilID, firstName and lastName are returned from the query. The returned values are stored in a PHP variable called $result. The contents of $result are shown below. 1 Agatha Bertrand 2 Polly N’mial The following section of PHP code is used to display the query results in an HTML table. ... Line 40 if ( mysqli_num_rows($result) > 0 ) Line 41 { Line 42 echo "<table>"; Line 43 // output each row of the table Line 44 while ($row = _____________________________________) Line 45 { Line 46 echo "_________".$row["pupilID"]."_________". $row["firstName"]. "_________". $row["lastName"]."_________"; Line 47 } Line 48 echo "</table>"; Line 49 } ...
The mysqli_num_rows() function at Line 42 is used to check that $result contains at least 1 row Line 44: $row= mysqli_fetch_array($result) Award 1 mark for correct use of mysqli_fetch_array() in line 44 Note: parameter must be correct Line 46: echo"<tr><td>".$row["pupilI D"]."</td><td>". $row["firstName"]. "</td><td>".$row["lastName" ]."</td></tr>"; Award 1 mark for correct use of <tr>, <td>, </td> and </tr> in line 46