yeah, you have to run the query twice (and you didn't execute the query using mysql_query())
The first time you run the query is just to get a count for how many rows there were and to be able to calculate many pages there will need to be. Then you have to run the query again using LIMIT (which limits how many results are actually being displayed per page).
There may be a parse error here or there; i'm tired and haven't tested this code, but give this a shot
<?php
$server = "localhost";
$username = "user";
$password = "pass";
$database = "your_db";
$table = "your_table";
// Connect To MySQL Server
@mysql_connect($server, $username, $password) or die("Couldn't Connect to Database");
// set number of results to display per page
$pagelimit = "10";
// *********** YOU NEED TO ACTUALLY EXECUTE THE QUERY W/OUT THE LIMIT. LATER ON YOU CAN ADD ON THE LIMIT
// *********** AFTER YOU'VE DONE YOUR CALCULATIONS
// *********** is tablename the name of your table? if not, don't forget to replace it
$query = mysql_query("SELECT id, first_name, last_name FROM tablename") or die(mysql_error());
// count number of matches
$totalrows = mysql_num_rows($query);
// determine how many pages there will be by using ceil() and dividing total rows by pagelimit
$pagenums = ceil ($totalrows/$pagelimit);
// if no value for page, page = 1
if (($_GET['page'] == '') || (!isset($_GET['page']))) {
$page='1';
} else {
$page = $_GET['page'];
}
// create a start value
$start = ($page-1) * $pagelimit;
// blank matches found
echo "<b>" . $totalrows . " matches found</b><br>\n";
// Showing Results 1 to 1 (or if you're page limit were 5) 1 to 5, etc.
$starting_no = $start + 1;
if ($totalrows - $start < $pagelimit) {
$end_count = $totalrows;
} elseif ($totalrows - $start >= $pagelimit) {
$end_count = $start + $pagelimit;
}
echo "Results $starting_no to $end_count shown.<br>\n";
// create dynamic next, previous, and page links
if ($totalrows - $end_count > $pagelimit) {
$var2 = $pagelimit;
} elseif ($totalrows - $end_count <= $pagelimit) {
$var2 = $totalrows - $end_count;
}
$space = " ";
// previous link
if ($page>1) {
echo "ยซ <a href='view.php?page=".($page-1)."' class=main>Previous" . $space . $pagelimit . "</a>" . $space . $space . "";
}
// dynamic page number links
for ($i=1; $i<=$pagenums; $i++) {
if ($i!=$page) {
echo " <a href='view.php?page=$i'>$i</a>";
}
else {
echo " <b>$i</b>";
}
}
// next link (make sure to change yourpage.php to the name of your page)
if ($page<$pagenums) {
echo "" . $space . $space . $space . $space . " <a href='view.php?page=".($page+1)."'>Next " . $var2 . "</a> ยป";
}
// ********** SAME HERE WITH YOUR TABLENAME. if your table is not named tablename, then change it below
$result = mysql_query("SELECT id, first_name, last_name FROM tablename LIMIT $start, $pagelimit") or die(mysql_error());
if (mysql_num_rows($result) > 0) {
echo "Found these entries in the database:<ul>";
echo "<ul>";
while ($r = mysql_fetch_array($result)) {
echo "<li><a href=\"process.php?id=" . $r["id"] . "\">" . $r["first_name"] . " " . $r["last_name"] . "</a>";
}
echo "</ul>";
} else {
echo "No data.";
}
mysql_free_result($result);
?>
Make sure to replace the mysql specs and 'tablename' with your mysql specs and your table name.
I've only been doing php seriously for about 4-5 months, but I started about a year ago just playing around w/it every once in a while. I've only read two books, there are a ton of awesome tutorials online, but I'd still reccomend having a book.
I started with (more for beginners) PHP Fast and Easy Web Development by Julie Meloni then moved up to
PHP and MySQL Web Development by Luke Welling and Laura Thomson. I'd definately reccomend this book, although I don't know if it's the best since I haven't read others to compare.
Good luck.
Cgraz