I have been working in dreamweaver to create a simple search on a database. I have a database named "library" It has one table: "main" and the fields in my table are "bookid - category - mediatype - title - author - year - notes "
Using dreamweaver, (php) I can get all of the records to print out in a table using recordsets. (so I know my connections are OK.) But I can not figure out how to display a recordset or query that just shows a list of all the items for a selected category (i.e. category=children.)
I want to have a form that users can select from a finite list of media types (i.e. biography, fiction, somethingelse) and return results matching their query. here is my search page code between my <body tags:
<form action="/result.php" method="get" name="categorysearch" id="categorysearch">
<select name="category" id="category">
<option>Biography
<option>Child Development
<option>Children
<option>Culture and Politics
</select>
<input type="submit" name="Submit" value="Submit">
</form>
Here is the result page tags:
<body>
<p>Library Holdings</p>
<p> </p>
<table border="1" cellpadding="2" cellspacing="4">
<tr>
<td>bookid</td>
<td>category</td>
<td>mediatype</td>
<td>title</td>
<td>author</td>
<td>year</td>
<td>notes</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_holdings['bookid']; ?></td>
<td><?php echo $row_holdings['category']; ?></td>
<td><?php echo $row_holdings['mediatype']; ?></td>
<td><?php echo $row_holdings['title']; ?></td>
<td><?php echo $row_holdings['author']; ?></td>
<td><?php echo $row_holdings['year']; ?></td>
<td><?php echo $row_holdings['notes']; ?></td>
</tr>
<?php } while ($row_holdings = mysql_fetch_assoc($holdings)); ?>
</table>
<?php require_once('Connections/library.php'); ?>
<?php
$maxRows_holdings = 10;
$pageNum_holdings = 0;
if (isset($HTTP_GET_VARS['pageNum_holdings'])) {
$pageNum_holdings = $HTTP_GET_VARS['pageNum_holdings'];
}
$startRow_holdings = $pageNum_holdings * $maxRows_holdings;
$colname_holdings = "1";
if (isset($HTTP_GET_VARS['category'])) {
$colname_holdings = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['category'] : addslashes($HTTP_GET_VARS['category']);
}
mysql_select_db($database_library, $library);
$query_holdings = sprintf("SELECT * FROM main WHERE category = '%s'", $colname_holdings);
$query_limit_holdings = sprintf("%s LIMIT %d, %d", $query_holdings, $startRow_holdings, $maxRows_holdings);
$holdings = mysql_query($query_limit_holdings, $library) or die(mysql_error());
$row_holdings = mysql_fetch_assoc($holdings);
if (isset($HTTP_GET_VARS['totalRows_holdings'])) {
$totalRows_holdings = $HTTP_GET_VARS['totalRows_holdings'];
} else {
$all_holdings = mysql_query($query_holdings);
$totalRows_holdings = mysql_num_rows($all_holdings);
}
$totalPages_holdings = ceil($totalRows_holdings/$maxRows_holdings)-1;
mysql_free_result($holdings);
?>
Records <?php echo ($startRow_holdings + 1) ?> to <?php echo min($startRow_holdings + $maxRows_holdings, $totalRows_holdings) ?> of <?php echo $totalRows_holdings ?>
</body>
</html>
The connections folder is uploaded and working correctly.
The error message I get is:
Library Holdings
HERE SHOWS A TABLE WITH ONLY THE FIELD TITLES, BUT NO RECORDS (7columns, a row)
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/aquas3/public_html/paxeducare/result.php on line 31
Records 1 to 10 of 70
The odd thing is, this counter is returning the correct total number of records for each search that I test. The part that I am messing up with seems to simply be how to display the results of the search.
Any Help is greatly appreciated!!!