<html>
<head>
<title> AR Book
List </title>
<STYLE TYPE="text/css">
BODY { font-size: 12pt; font-family: Arial, Helvetica; }
TD { font-size: 12pt; font-family: Arial, Helvetica; }
</STYLE>
</head>
<body>
<?php
//Colors to Alternate Rows
$color1 = "#F5F5F5";
$color2 = "#FFFFFF";
$row_count = 0;
// Connect to the database server
if (!$dbcnx) {
die( '<p>Unable to connect to the ' .
'database server at this time.</p>' );
}
// Select the database
die( '<p>Unable to locate the ' .
'database at this time.</p>' );
}
?>
<?php
// If the Search form has already been submitted
if(isset($_POST['Submit'])) {
//Print the table header
<div align="center">
<p><h1> Search Results </h1></p>
<p>
<table width=90% cellpadding=5 cellspacing=1 bgcolor=cccccc border=0>
<tr>
<td bgcolor=f5f5f5>TestNum</td>
<td bgcolor=f5f5f5>Title</td>
<td bgcolor=f5f5f5>Author</td>
<td bgcolor=f5f5f5>ReadingLevel</td>
<td bgcolor=f5f5f5>PointValue</td>");
//MySQL SELECT Query to sort out form data from search
('Author' LIKE '%$Author%') AND
('Title' LIKE '%$Title%') AND
('ReadingLevel' BETWEEN '$ReadingLow' AND '$ReadingHigh') AND
('PointValue' BETWEEN '$PointLow' AND '$PointHigh')
ORDER BY 'Title','Author'");
if (!$result) {
'</p>');
}
$testnum = $row["TestNum"];
$title = $row["Title"];
$author = $row["Author"];
$readinglevel = $row["ReadingLevel"];
$pointvalue = $row["PointValue"];
/* Now we do this small line which is basically going to tell
PHP to alternate the colors between the two colors we defined above. */
$row_color = ($row_count % 2) ? $color1 : $color2;
// Echo your table row and table data that you want to be looped over and over here.
<tr bgcolor="$row_color">
<td>$testnum</td>
<td>$title</td>
<td>$author</td>
<td>$readinglevel</td>
<td>$pointvalue</td>
</tr>";
// Add 1 to the row count
$row_count++;
}
}
// If the Form was not submitted, display all the books below
else {
<div align="center">
<table border=0 cellspacing=3 cellpadding=3>
<tr valign=middle><td>
<p><h1> AR Book List Database </h1></p>
</td><td align=right>
<p><b> Search the Book List Database</b></p>
<form action=" . $_SERVER['PHP_SELF'] . " method="post">
Search By Author: <input type=textarea name="Author">
<br />Search By Title: <input type=textarea name="Title">
<br />Search By Reading Level: Between <input type=text size=4 name="ReadingLow"> and <input type=text size=4 name="ReadingHigh">
<br />Search By Point Value: Between <input type=text size=4 name="PointLow"> and <input type=text size=4 name="PointHigh">
<br /><input type="submit" value="Submit" name="Submit"></form>
</td></tr>
</table>
<table width=90% cellpadding=5 cellspacing=1 bgcolor=cccccc border=0>
<tr>");
echo("<td bgcolor=f5f5f5><a href="" . $_SERVER['PHP_SELF'] . "">TestNum</td>");
echo("<td bgcolor=f5f5f5><a href="" . $_SERVER['PHP_SELF'] . "?orderby=title
">" .
"Title</a></td>");
echo("<td bgcolor=f5f5f5><a href="" . $_SERVER['PHP_SELF'] . "?orderby=author
">" .
"Author</a></td>");
echo("<td bgcolor=f5f5f5>ReadingLevel</td>");
echo("<td bgcolor=f5f5f5>PointValue</td>");
if ($orderby == title) {
// Sort books by title
$result = @
mysql_query('SELECT * FROM booklist ORDER BY Title');
if (!$result) {
'</p>');
}
} elseif ($orderby == author) {
// Sort books by author, then by title
$result = @
mysql_query('SELECT * FROM booklist ORDER BY Author,Title');
if (!$result) {
'</p>');
}
} else {
// Default - sort books by test number
$result = @
mysql_query('SELECT * FROM booklist ORDER BY TestNum');
if (!$result) {
'</p>');
}
}
$testnum = $row["TestNum"];
$title = $row["Title"];
$author = $row["Author"];
$readinglevel = $row["ReadingLevel"];
$pointvalue = $row["PointValue"];
/* Now we do this small line which is basically going to tell
PHP to alternate the colors between the two colors we defined above. */
$row_color = ($row_count % 2) ? $color1 : $color2;
// Echo your table row and table data that you want to be looped over and over here.
<tr bgcolor="$row_color">
<td>$testnum</td>
<td>$title</td>
<td>$author</td>
<td>$readinglevel</td>
<td>$pointvalue</td>
</tr>";
// Add 1 to the row count
$row_count++;
}
}
?>
</table>
</div>
</body>
</html>