|
<P> = new paragraph
<HR> = horizontal line
<UL> A unordered list environment
<LI>
</UL>
<OL> An ordered list environment
<LI>
</OL>
|
Hello <P> <HR> <P> List 1: <UL> <LI> ABC <LI> XYZ </UL> <P> List 2: <OL> <LI> ABC <LI> XYZ </OL> <P> |
Will look like this when displayed in a browser:
|
Hello
List 1:
List 2:
|
<TABLE bgcolor="lightcyan" BORDER="5"> <TR> // <TR> means: Table Row <TH> Header 1 </TH> // <TH> means: Table header <TH> Header 2 </TH> <TH> Header 2 </TH> </TR> <TR> <TD> Item 1 of row 1</TD> // <TD> means: Table data <TD> Item 2 of row 1</TD> <TD> Item 3 of row 1</TD> </TR> <TR> <TD> Item 1 of row 2</TD> <TD> Item 2 of row 2</TD> <TD> Item 3 of row 2</TD> </TR> </TABLE> |
This will be displayed as follows in a web brower:
| Header 1 | Header 2 | Header 2 |
|---|---|---|
| Item 1 of row 1 | Item 2 of row 1 | Item 3 of row 1 |
| Item 1 of row 2 | Item 2 of row 2 | Item 3 of row 2 |
|
<html>
<head>
<title> MySQL Test 1</title>
</head>
<body>
<H3>
<HR>
Accessing a Database through a <I>Web browser</I> using PHP
<HR>
</H3>
<P>
<UL>
<?php
$conn = mysqli_connect("holland.mathcs.emory.edu","cs377", "abc123", "companyDB");
if (mysqli_connect_errno()) # ----------- check connection error
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit(1);
}
$query = 'select fname, lname, salary from employee';
if ( ( $result = mysqli_query($conn, $query)) == NULL ) # Execute query
{
printf("Error: %s\n", mysqli_error($conn));
exit(1);
}
// Additions a hightlighted in red
printf("<P>\nSelect returned %d rows.\n<P>\n", mysqli_num_rows($result));
print("<P>\n");
print("<UL>\n");
print("<TABLE bgcolor=\"lightyellow\" BORDER=\"5\">\n");
# ------------------------------------------------------------
# Print names of attributes in one row of the table
# ------------------------------------------------------------
print("<TR bgcolor=\"lightcyan\">\n"); # Start row of HTML table
while ( ($field_details = mysqli_fetch_field($result)) != NULL )
{
print ("<TH>" . $field_details->name . "</TH>"); # One item in row
}
print ("</TR>\n"); # End row of HTML table
# ------------------------------------------------------------
# Print the tuples
# ------------------------------------------------------------
while ( ($row = mysqli_fetch_row( $result ) ) != NULL )
{
# Print one tuple as a row in table
print("<TR>\n"); # Start row
for ( $i = 0; $i < count($row); $i++ )
{
print ("<TD>" . $row[$i] . "</TD>"); # Print values in one row
}
print ("</TR>\n"); # End row
}
print("</TABLE>\n");
print("</UL>\n");
print("<P>\n");
mysqli_free_result($result);
mysqli_close($conn);
?>
</UL>
<P>
<HR>
<HR>
</body>
</html>
|
Explanation:
|
Output of the MySQL PHP script:
.....
..... (HTML headers omitted)
<P>
Select returned 8 rows.
<P>
<P>
<UL>
<TABLE bgcolor="lightyellow" BORDER="5">
<TR>
<TH>fname</TH><TH>lname</TH><TH>salary</TH></TR>
<TR>
<TR>
<TD>John</TD><TD>Smith</TD><TD>50000.00</TD></TR>
<TR>
<TD>Frankl</TD><TD>Wong</TD><TD>40000.00</TD></TR>
<TR>
<TD>Alicia</TD><TD>Zelaya</TD><TD>25000.00</TD></TR>
<TR>
<TD>Jennif</TD><TD>Wallace</TD><TD>43000.00</TD></TR>
<TR>
<TD>Ramesh</TD><TD>Narayan</TD><TD>38000.00</TD></TR>
<TR>
<TD>Joyce</TD><TD>English</TD><TD>25000.00</TD></TR>
<TR>
<TD>Ahmad</TD><TD>Jabbar</TD><TD>25000.00</TD></TR>
<TR>
<TD>James</TD><TD>Borg</TD><TD>55000.00</TD></TR>
</TABLE>
</UL>
<P>
....
....
|
Enter this URL in a web browser:
http://holland.mathcs.emory.edu/~cs377001/Web/employee2.php |
(You can right click in the web browser and select View Page Source to see the output)