By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,950 Members | 1,888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,950 IT Pros & Developers. It's quick & easy.

to show fixed no. of rows (data) in one pages

P: 99
HI, i have large code to show the data access from a table. Actually i want to show 10 records at a time in one pages and remaining records in the othere pages. as for example
I have a table called employee and in this table there are more than 50 rows (records). so i used the mysql query "Select * from employee". I want to show only 10 records in one pages. Please help me and give me the code. thanking you
Oct 16 '07 #1
Share this Question
Share on Google+
6 Replies


ronverdonk
Expert 2.5K+
P: 4,258
" ...... Please help me and give me the code. thanking you ....."
You may not know this, but this site is about helping developers with problems with code, environment and other problems they encounter. This is not a code-producing site.

So show us the code you have developed so far and we can see where to help you.

Ronald
Oct 16 '07 #2

P: 99
thanks i will post the code tomorrow thanks for the response
You may not know this, but this site is about helping developers with problems with code, environment and other problems they encounter. This is not a code-producing site.

So show us the code you have developed so far and we can see where to help you.

Ronald
Oct 16 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
thanks i will post the code tomorrow thanks for the response
Please do not forget to include that code with code tags.

See the Posting Guidelines on how to do that.

Ronald
Oct 16 '07 #4

P: 3
HI, i have large code to show the data access from a table. Actually i want to show 10 records at a time in one pages and remaining records in the othere pages. as for example
I have a table called employee and in this table there are more than 50 rows (records). so i used the mysql query "Select * from employee". I want to show only 10 records in one pages. Please help me and give me the code. thanking you
I think u have to keep pagination asper my knowledge I hope this code be usefull to you.
[php]
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$query = "SELECT count(*) FROM table WHERE ...";
$result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 15;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM table $limit";
$result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR);
if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}
echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
}
[/php]
Oct 17 '07 #5

P: 99
Thanks you very much somasekhar for helping me..have a gud day

I think u have to keep pagination asper my knowledge I hope this code be usefull to you.


if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$query = "SELECT count(*) FROM table WHERE ...";
$result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 15;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM table $limit";
$result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR);
if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}
echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
}
Oct 17 '07 #6

ronverdonk
Expert 2.5K+
P: 4,258
somasekhar: Next time enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

moderator
Oct 17 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.