Basic knowledge: sorts the IDs by orderbyiddesc or orderbyidasc, and then judges that the id is smaller than the id of the current article than the current idor. the SQL statement of the instance is as follows:
Basic knowledge: sort the id by id desc or order by id asc, and then judge whether the current id is greater than or less than the current article id. the SQL statement of the instance is as follows:
Select * from news where id <$ id order by id desc limit 0, 1
Select * from news where id> $ id order by id desc limit 0, 1
Table structure 'string _ find'
- Create table if not exists 'string _ find '(
- 'Id' int (4) not null auto_increment,
- 'Charlist' varchar (100) default NULL,
- Primary key ('id ')
- ) ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 7;
Export the data in the table 'string _ find'
- Insert into 'string _ find '('id', 'charlist') VALUES
- (1, 'pioneer Deng '),
- (2, 'pioneer Deng '),
- (5, 'fdafdsaf '),
- (6, 'www .phpfensi.com ');
Now everything is ready. let's take a look at the operation method below:
- */
- Mysql tutorial _ pconnect ('localhost', 'root', 'root') or die (mysql_error ());
- Mysql_select_db ('CC ');
- Mysql_query ("set names 'gbk '");
- $ Cid = 5; // The number of your current article
- $ SQL = "select * from string_find where id> $ cid order by id desc limit 0, 1"; // previous article
- $ Sql1 = "select * from string_find where id <$ cid order by id asc limit 0, 1"; // next article
-
- $ Result = mysql_query ($ SQL );
- If (mysql_num_rows ($ result ))
- {
- $ Rs = mysql_fetch_array ($ result );
- Echo "previous". $ rs [0];
- }
- Else
- {
- Echo "no ";
- }
-
- $ Result1 = mysql_query ($ sql1 );
- If (mysql_num_rows ($ result1 ))
- {
- $ Rs1 = mysql_fetch_array ($ result1 );
- Echo "next". $ rs1 [0];
- }
- Else
- {
- Echo "no ";
- }