Im trying to pull a results set into a spaned page format with prev 123... next links at the bottom.
the user passes 1-3 variables (author & title and a sort option) to a php from a forms page.
when i use the script as is i get an error when i click on the link, (the page count seems about right for the number of records expected)
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in test.php on line 6
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in test.php on line 20
if i try to pass the variabes "$author $title $sort" in the url the variables are replaced with the data from the last displayed record so when i click on the link I get the last record displayed and thats all
how can i pass the variables as submitted by the form?
php as follows:
<?
/ connection information /
$hostname = "XXX";
$username = "XXX";
$password = "XXX";
$dbName = "Foo";
$table = "books1";
/ make connection to database / MYSQL_CONNECT($hostname, $username, $password) OR DIE( "Unable to connectto database");@mysql_select_db("$dbName") or die( "Unable to select database"); if ($sort == "") if ($title == "") {$title = '%';} if ($author == "") {$author = '%';}
$sql = "SELECT * FROM $table WHERE title LIKE '%$title%' AND author LIKE '%$author%' ORDER BY $sort";
$limit = 20; // rows to return
$numresults = mysql_query($sql);
$numrows = mysql_num_rows($numresults);
// has been passed to script, if not use 1
if (empty($offset)) {
$offset = 1;
}
$offset = $limit * ($offset - 1);
// get results
$result = mysql_query("$sql limit $offset,$limit");
// display the results returned
WHILE ($data=MYSQL_FETCH_ARRAY($result)){
$number = mysql_numrows($result);
if (!$number) print("No \n");
/ Print the relevant information /
$i = 0; PRINT " $number books found:<p>"; PRINT " To order call 212-439-9194, fax 212-744-1626 or email info@archivia.com<p>"; PRINT "<table width=100% cellpadding=5 cellspacing=5>";
PRINT " <TR bgcolor=black> <td>description</td></tr>";
WHILE ($i < $number): $author = mysql_result($result, $i,"author"); $title = mysql_result($result,$i,"title"); $bookid = mysql_result($result,$i,"bookid"); $price = mysql_result($result,$i,"price"); $description = mysql_result($result,$i,"description"); $image = mysql_result($result,$i,"image"); { PRINT "<table valign=top width=100% cellspacing=5 cellpadding=5><tr><td width=15%> $image</td>
<td width=85%> $author<br> $title<br><br> $description(#$bookid) <br> \$$price</td>
</tr>
<br><hr><br>
</table>";
}$i++;ENDWHILE;PRINT "</table>";
}
// do the links to other results
if ($offset < 1) { // bypass PREV link if offset is 0
$refpage = $offset - 1;
print "<a href='$PHP_SELF?&page=$refpage'> PREV</a> \n";
}
// calculate number of pages needing links
$numpages = intval($numrows / $limit);
// $numpages now contains int of pages needed unless there is a remainder from division
if ($numrows % $limit) {
// has remainder so add one page
$numpages++;
}
for ($i = 1; $i <= $numpages; $i++) { // loop thru
if($offset != $i) {
print "<a href='$PHP_SELF?&page=$i'>";
}
print $i;
if($offset != $i) {
print "</a>";
}
print " \n";
}
// check to see if last page
if ($offset < $numpages) {
// not last page so give NEXT link
$refpage = $offset + 1;
print "<a href='$PHP_SELF?&page=$refpage'> NEXT</a><p>\n";
}
?>
please help, im goin crazy on this one
Doug