After repeated regions are added, ascending, without paging

Source: Internet
Author: User
After repeated regions are added, you can add them in ascending order. if you want to add repeated regions on a webpage, 50 entries of information cannot be displayed in ascending order. The old information at the bottom of the page is at the top of the page. However, when more than 50 pieces of information are added, 1-50 pieces of information are displayed on the page. I don't want to display any old information when I add a new message. Thank you.


Reply to discussion (solution)

If it is read from the database, desc it first and then limit it to get the first 50.
Select * from table desc order by id limit 0, 49
If you want to sort in ascending order, select * from (select * from table order by id desc limit) order by id asc

$ CurrentPage = $ _ SERVER ["PHP_SELF"];
$ MaxRows_R1 = 10;
$ PageNum_R1 = 0;
If (isset ($ _ GET ['pagenum _ r1']) {
$ PageNum_R1 = $ _ GET ['pagenum _ r1'];
}
$ StartRow_R1 = $ pageNum_R1 * $ maxRows_R1;
$ MaxRows_R1 = 35;
$ PageNum_R1 = 0;
If (isset ($ _ GET ['pagenum _ r1']) {
$ PageNum_R1 = $ _ GET ['pagenum _ r1'];}
$ StartRow_R1 = $ pageNum_R1 * $ maxRows_R1;
Mysql_select_db ($ database_liandb, $ liandb );
$ Query_R1 = "SELECT * FROM mydb1 order by id ASC ";
$ Query_limit_R1 = sprintf ("% s LIMIT % d, % d", $ query_R1, $ startRow_R1, $ maxRows_R1 );
$ R1 = mysql_query ($ query_limit_R1, $ liandb) or die (mysql_error ());
$ Row_R1 = mysql_fetch_assoc ($ R1 );
How should I add it?


$ Query_R1 = "SELECT * FROM mydb1 order by id desc ";
$ Query_limit_R1 = sprintf ("% s LIMIT % d, % d", $ query_R1, $ startRow_R1, $ maxRows_R1 );
$ Query_limit_R1_Supper = "select * from (". $ query_limit_R1. ") order by id asc"
$ R1 = mysql_query ($ query_limit_R1_Supper, $ liandb) or die (mysql_error ());
$ Row_R1 = mysql_fetch_assoc ($ R1 );

$ Query_limit_R1 quotation marks may be missing. If not, debug it.

$ PageNum_R1 = $ _ GET ['pagenum _ r1'];}
$ StartRow_R1 = $ pageNum_R1 * $ maxRows_R1;
Mysql_select_db ($ database_liandb, $ liandb );
$ Query_R1 = "SELECT * FROM mydb1 order by id DESC ";
$ Query_limit_R1 = sprintf ("% s LIMIT % d, % d", $ query_R1, $ startRow_R1, $ maxRows_R1 );
$ Query_limit_R1_Supper = "select * from (". $ query_limit_R1. ") order by id asc ";
$ R1 = mysql_query ($ query_limit_R1, $ liandb) or die (mysql_error ());
$ Row_R1 = mysql_fetch_assoc ($ R1 );

This is a descending order, and the ascending order does not work.

Wrong...
$ R1 = mysql_query ($ query_limit_R1_Supper, $ liandb) or die (mysql_error ());
It is not $ query_limit_R1

Please fill in the details for me. I am a newbie, thank you.

$pageNum_R1 = $_GET['pageNum_R1'];}$startRow_R1 = $pageNum_R1 * $maxRows_R1;mysql_select_db($database_liandb, $liandb);$query_R1 = "SELECT * FROM mydb1 ORDER BY id desc";$query_limit_R1=sprintf("%s LIMIT %d, %d", $query_R1, $startRow_R1, $maxRows_R1);$query_limit_R1_Supper ="select * from (".$query_limit_R1.") order by id asc "$R1 = mysql_query($query_limit_R1_Supper, $liandb) or die(mysql_error());$row_R1 = mysql_fetch_assoc($R1);

$ PageNum_R1 = $ _ GET ['pagenum _ r1'];}
$ StartRow_R1 = $ pageNum_R1 * $ maxRows_R1;
Mysql_select_db ($ database_liandb, $ liandb );
$ Query_R1 = "SELECT * FROM mydb1 order by id DESC ";
$ Query_limit_R1 = sprintf ("% s LIMIT % d, % d", $ query_R1, $ startRow_R1, $ maxRows_R1 );
$ R1 = mysql_query ($ query_limit_R1_Supper, $ liandb) or die (mysql_error ());
$ Row_R1 = mysql_fetch_assoc ($ R1 );

Error message: the query is empty.

$ Query_limit_R1 = sprintf ("% s LIMIT % d, % d", $ query_R1, $ startRow_R1, $ maxRows_R1 );
$ R1 = mysql_query ($ query_limit_R1_Supper, $ liandb) or die (mysql_error ());
Is the row between the two rows deleted?
$ Query_limit_R1 = sprintf ("% s LIMIT % d, % d", $ query_R1, $ startRow_R1, $ maxRows_R1 );
$ Query_limit_R1_Supper = "select * from (". $ query_limit_R1. ") order by id asc"
$ R1 = mysql_query ($ query_limit_R1_Supper, $ liandb) or die (mysql_error ());
What about the middle line?

$ PageNum_R1 = $ _ GET ['pagenum _ r1'];}
$ StartRow_R1 = $ pageNum_R1 * $ maxRows_R1;
Mysql_select_db ($ database_liandb, $ liandb );
$ Query_R1 = "SELECT * FROM mydb1 order by id DESC ";
$ Query_limit_R1 = sprintf ("% s LIMIT % d, % d", $ query_R1, $ startRow_R1, $ maxRows_R1 );
$ Query_limit_R1_Supper = "select * from (". $ query_limit_R1. ") order by id asc ";
$ R1 = mysql_query ($ query_limit_R1_Supper, $ liandb) or die (mysql_error ());
$ Row_R1 = mysql_fetch_assoc ($ R1 );

Error message: Each derived table must have its own alias.

$ Query_limit_R1_Supper = "select * from (". $ query_limit_R1. ") M, order by id asc ";

If (! Function_exists ("GetSQLValueString ")){
Function GetSQLValueString ($ theValue, $ theType, $ theDefinedValue = "", $ theNotDefinedValue = "")
{
If (PHP_VERSION <6 ){
$ TheValue = get_magic_quotes_gpc ()? Stripslashes ($ theValue): $ theValue;
}

$ TheValue = function_exists ("mysql_real_escape_string ")? Mysql_real_escape_string ($ theValue): mysql_escape_string ($ theValue );

Switch ($ theType ){
Case "text ":
$ TheValue = ($ theValue! = "")? "'". $ TheValue. "'": "NULL ";
Break;
Case "long ":
Case "int ":
$ TheValue = ($ theValue! = "")? Intval ($ theValue): "NULL ";
Break;
Case "double ":
$ TheValue = ($ theValue! = "")? Doubleval ($ theValue): "NULL ";
Break;
Case "date ":
$ TheValue = ($ theValue! = "")? "'". $ TheValue. "'": "NULL ";
Break;
Case "defined ":
$ TheValue = ($ theValue! = "")? $ TheDefinedValue: $ theNotDefinedValue;
Break;
}
Return $ theValue;
}
}

$ CurrentPage = $ _ SERVER ["PHP_SELF"];

$ MaxRows_R1 = 10;
$ PageNum_R1 = 0;
If (isset ($ _ GET ['pagenum _ r1']) {
$ PageNum_R1 = $ _ GET ['pagenum _ r1'];
}
$ StartRow_R1 = $ pageNum_R1 * $ maxRows_R1;
$ MaxRows_R1 = 35;
$ PageNum_R1 = 0;
If (isset ($ _ GET ['pagenum _ r1']) {
$ PageNum_R1 = $ _ GET ['pagenum _ r1'];}
$ StartRow_R1 = $ pageNum_R1 * $ maxRows_R1;
Mysql_select_db ($ database_liandb, $ liandb );
$ Query_R1 = "SELECT * FROM mydb1 order by id desc ";
$ Query_limit_R1 = sprintf ("% s LIMIT % d, % d", $ query_R1, $ startRow_R1, $ maxRows_R1 );
$ Query_limit_R1_Supper = "select * from (". $ query_limit_R1. ") M, order by id asc ";
$ R1 = mysql_query ($ query_limit_R1_Supper, $ liandb) or die (mysql_error ());
$ Row_R1 = mysql_fetch_assoc ($ R1 );

If (isset ($ _ GET ['totalrows _ r1']) {
$ TotalRows_R1 = $ _ GET ['totalrows _ r1'];
} Else {
$ All_R1 = mysql_query ($ query_R1 );
$ TotalRows_R1 = mysql_num_rows ($ all_R1 );
}
$ TotalPages_R1 = ceil ($ totalRows_R1/$ maxRows_R1)-1;

$ QueryString_R1 = "";
If (! Empty ($ _ SERVER ['query _ string']) {
$ Params = explode ("&", $ _ SERVER ['query _ string']);
$ NewParams = array ();
Foreach ($ params as $ param ){
If (stristr ($ param, "pageNum_R1") = false &&
Stristr ($ param, "totalRows_R1") = false ){
Array_push ($ newParams, $ param );
}
}
If (count ($ newParams )! = 0 ){
$ QueryString_R1 = "&". htmlentities (implode ("&", $ newParams ));
}
}
$ QueryString_R1 = sprintf ("& totalRows_R1 = % d % s", $ totalRows_R1, $ queryString_R1 );
?>

There is an error in your SQL syntax; check the manual, corresponding to your MySQL server version for the correct syntax using the nearby Order id asc on Line 1

$ Query_limit_R1_Supper = "select M. * from (". $ query_limit_R1. ") M, order by id asc ";

The same error

There is an error in your SQL syntax; check the manual, corresponding to your MySQL server version for the correct syntax using the nearby Order id asc on Line 1

$ Query_limit_R1_Supper = "select M. * from (". $ query_limit_R1. ") M order by id asc ";
Add a comma .. Sorry.

Thanks for your patience and help, but I don't know how to choose a wonderful answer?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.