latheesan
06-23-2006, 10:05 PM
Hello. I'm working on a new script and found my self stuck on a new hurdle. Hope you guys help me out once again.
I am working on pagination for my script and this is how the coding looks so far:
<?php
/* Connect To MySQL Server */
mysql_connect($host, $user, $pass) or trigger_error("SQL", E_USER_ERROR);
mysql_select_db($db) or trigger_error("SQL", E_USER_ERROR);
/* Obtain The Required Page Number */
if(isset($_GET["N"]))
{
$pageno = $_GET["N"];
} else {
$pageno = 1;
}
/* Identify How Many Rows Are Available In The Database */
$query = "SELECT count(*) FROM users WHERE active = '1'";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
/* Calculate Number of $lastpage */
$rows_per_page = 5;
$lastpage = ceil($numrows/$rows_per_page);
/* Ensure Pageno is Within Range */
$pageno = (int)$pageno;
if($pageno < 1)
{
$pageno = 1;
}
else
if($pageno > $lastpage)
{
$pageno = $lastpage;
}
/* Construct LIMIT Clause */
$limit = 'LIMIT ' . ($pageno - 1) * $rows_per_page . ',' . $rows_per_page;
/* Query Database Collect Data */
$query = "SELECT * FROM users WHERE active = '1' $limit";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
mysql_close();
/* Display Data */
$i = 0;
while($i < $rows_per_page)
{
/* Construct Data */
$myspace_id = mysql_result($result, $i, "myspace_id");
$name = mysql_result($result, $i, "name");
$age = mysql_result($result, $i, "age");
$category = mysql_result($result, $i, "category");
$notes = mysql_result($result, $i, "notes");
$photo = mysql_result($result, $i, "photo");
/* Print Data Here */
/* Run Loop */
$i++;
}
?>
I had 13 records in the db, so Page 1, 2 worked fine. When i clicked on page 3, i started to get this error:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 3 on MySQL result index 10 in C:\WWW\xampp\htdocs\html\Home.php on line 78
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 3 on MySQL result index 10 in C:\WWW\xampp\htdocs\html\Home.php on line 79
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 3 on MySQL result index 10 in C:\WWW\xampp\htdocs\html\Home.php on line 80
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 3 on MySQL result index 10 in C:\WWW\xampp\htdocs\html\Home.php on line 81
etc...
I have a slight idea why this error is caused. I am thinking this error is shown because there isnt enough records in the data to fulfil the LIMIT construct on page 3. If thats the case, then, how can you solve such a problem? I mean, get the script to only construct the last page for only the amount of records left...
Thanks in advance for your input guys :)
I am working on pagination for my script and this is how the coding looks so far:
<?php
/* Connect To MySQL Server */
mysql_connect($host, $user, $pass) or trigger_error("SQL", E_USER_ERROR);
mysql_select_db($db) or trigger_error("SQL", E_USER_ERROR);
/* Obtain The Required Page Number */
if(isset($_GET["N"]))
{
$pageno = $_GET["N"];
} else {
$pageno = 1;
}
/* Identify How Many Rows Are Available In The Database */
$query = "SELECT count(*) FROM users WHERE active = '1'";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
/* Calculate Number of $lastpage */
$rows_per_page = 5;
$lastpage = ceil($numrows/$rows_per_page);
/* Ensure Pageno is Within Range */
$pageno = (int)$pageno;
if($pageno < 1)
{
$pageno = 1;
}
else
if($pageno > $lastpage)
{
$pageno = $lastpage;
}
/* Construct LIMIT Clause */
$limit = 'LIMIT ' . ($pageno - 1) * $rows_per_page . ',' . $rows_per_page;
/* Query Database Collect Data */
$query = "SELECT * FROM users WHERE active = '1' $limit";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
mysql_close();
/* Display Data */
$i = 0;
while($i < $rows_per_page)
{
/* Construct Data */
$myspace_id = mysql_result($result, $i, "myspace_id");
$name = mysql_result($result, $i, "name");
$age = mysql_result($result, $i, "age");
$category = mysql_result($result, $i, "category");
$notes = mysql_result($result, $i, "notes");
$photo = mysql_result($result, $i, "photo");
/* Print Data Here */
/* Run Loop */
$i++;
}
?>
I had 13 records in the db, so Page 1, 2 worked fine. When i clicked on page 3, i started to get this error:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 3 on MySQL result index 10 in C:\WWW\xampp\htdocs\html\Home.php on line 78
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 3 on MySQL result index 10 in C:\WWW\xampp\htdocs\html\Home.php on line 79
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 3 on MySQL result index 10 in C:\WWW\xampp\htdocs\html\Home.php on line 80
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 3 on MySQL result index 10 in C:\WWW\xampp\htdocs\html\Home.php on line 81
etc...
I have a slight idea why this error is caused. I am thinking this error is shown because there isnt enough records in the data to fulfil the LIMIT construct on page 3. If thats the case, then, how can you solve such a problem? I mean, get the script to only construct the last page for only the amount of records left...
Thanks in advance for your input guys :)
