Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /path/... on line 38
here is what i am trying to do...i want to add a paging system to my blog so that the page isnt 50 miles high...
here is what i have going on...
test.php:
Code: Select all
<?php
include('dbconfig.php');
$total = 130;
$limit = 20;
$page = 3;
$numPages = ceil($total / $limit);
function getPagerData($numPages, $limit, $page)
{
$numPages = (int) $numPages;
$limit = max((int) $limit, 1);
$page = (int) $page;
$numPages = ceil($numPages / $limit);
$page = max($page, 1);
$page = min($page, $numPages);
$offset = ($page - 1) * $limit;
$ret = new stdClass;
$ret->offset = $offset;
$ret->limit = $limit;
$ret->numPages = $numPages;
$ret->page = $page;
return $ret;
}
// get the pager input values
$page = $_GETї'page'];
$limit = 20;
$result = mysql_query("select count(*) from $entrytable");
$total = mysql_result($result, 0, 0); //******error line******
// work out the pager values
$pager = getPagerData($total, $limit, $page);
$offset = $pager->offset;
$limit = $pager->limit;
$page = $pager->page;
// use pager values to fetch data
$query = "select * from $entrytable order by someField limit $offset, $limit";
$result = mysql_query($query);
// use $result here to output page content
?>
<table align="center" width="80%">
<td align="center" width="100%">
<?php echo "$result"; ?>
</td>
</table>
<?php
// output paging system (could also do it before we output the page content)
if ($page == 1) // this is the first page - there is no previous page
echo "Previous";
else // not the first page, link to the previous page
echo "<a href="test.php?page=" . ($page - 1) . "">Previous</a>";
for ($i = 1; $i <= $pager->numPages; $i++) {
echo " | ";
if ($i == $pager->page)
echo "Page $i";
else
echo "<a href="test.php?page=$i">Page $i</a>";
}
if ($page == $pager->numPages) // this is the last page - there is no next page
echo "Next";
else // not the last page, link to the next page
echo "<a href="test.php?page=" . ($page + 1) . "">Next</a>";
?>Code: Select all
<?php
// MySQL database connection information
$host = "localhost"; // MySQL host
$username = "user"; // MySQL username
$userpass = "pass"; // MySQL password
$database = "myDB"; // MySQL database
// MySQL database table information
$entrytable = "blog_post"; // MySQL table to hold blog entries
$commenttable = "blog_comm"; // MySQL table to hold comments
?>so what gives? any help will be very helpful! (let me know if you need more info)
Thanks,
Matt