Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP: Output Formatting

Similar presentations


Presentation on theme: "PHP: Output Formatting"— Presentation transcript:

1 PHP: Output Formatting
FdSc Module 109 Server side scripting and Database design 2011

2 basicSelection.php This script did not format the data very well
We should use tables to display data Table tags <table> </table> <tr> </tr> a row <td> </td> a data cell We can also use print to output HTML

3 print print("<table width='500' border='1'>");
This command will create a table with a width of 500 pixels and a border Make this the first command in the modified basicSelection.php (after the if ($connectionSuccess == 1) { )

4 Be more selective Use SQL to retrieve the title and author $result = mysql_query("SELECT title, author FROM books"); while ($row = mysql_fetch_array($result)) {

5 Assign variables Assign the results of the query to variables $Title = $row['title']; $Author = $row['author'];

6 Print the results in table cells
print("<tr>"); print("<td>$Title </td><td> $Author</td>"); print("</tr>");

7 Complete code if ($connectionSuccess == 1) { print("<table width='500' border='1'>"); $result = mysql_query("SELECT title, author FROM books"); while ($row = mysql_fetch_array($result)) { $Title = $row['title']; $Author = $row['author']; print("<tr>"); print("<td>$Title </td><td> $Author</td>"); print("</tr>"); } mysql_free_results($result); //free up server memory

8 Appearance


Download ppt "PHP: Output Formatting"

Similar presentations


Ads by Google