浣犵殑鐩稿叧闃呰诲熲滅浉鍏斥濆悧
銆銆涓轰簡澧炲姞鍐呴摼锛屼篃涓轰簡鏂逛究鐢ㄦ埛娴忚堟洿澶氱浉鍏崇殑缃戦〉锛岃稿氱綉绔欓兘璁剧疆浜“鐩稿叧闃呰”锛屾垨“鐚滀綘鍠滄”涔嬬被鐨勬爮鐩锛岀劧鑰屾垜鍙戠幇鏈変笉灏戠綉绔欑殑鐩稿叧闃呰绘瘡涓缃戦〉閮芥槸涓鏍风殑锛屽苟涓旀湁鏃剁浉鍏虫т篃涓嶅己锛岀悽纾ㄥ悗鍙戠幇锛屽師鏉ョ珯闀胯剧疆鐨勭浉鍏抽槄璇诲叾瀹炴槸鏁版嵁琛ㄩ噷鐨勬渶杩戝嚑鏉¤板綍缃浜嗭紝瀹冧娇鐢ㄧ殑SQL鏌ヨ㈣鍙ュぇ鑷存槸杩欐牱锛
銆銆select id,title from mytb order by id desc limit 8
銆銆杩欐牱鐨勬煡璇锛屾湁鏄庢樉鐨勪袱涓缂洪櫡锛
銆銆1. 鏌ユ壘鍒扮殑缁撴灉骞朵笉鑳戒繚璇佹槸鐩稿叧鐨;
銆銆2.浼氱収鎴愬ぇ閲忕殑椤甸潰浣跨敤浜嗙浉鍚岀殑鐩稿叧闃呰伙紝鐢ㄦ埛浣撻獙涓嶅ソ锛屽悓鏃朵篃鍗犳嵁浜嗗叾瀹冩暟鎹鏇濆厜鐨勬満浼氥
銆銆鍏跺疄锛岃繖涓鏌ヨ㈣鍙ョ◢寰浼樺寲涓嬶紝灏卞彲浠ユ敼鍠“鐩稿叧闃呰”锛屾柟娉曞備笅锛
銆銆鍒嗘瀽锛氶栧厛鍒ゆ柇褰撳墠缃戦〉鐨勬暟鎹甶d鍦ㄦ暣涓琛ㄤ腑鎵澶勭殑浣嶇疆锛屽垎涓轰笁绉嶆儏鍐(鍙8鏉¤板綍涓轰緥)锛
銆銆1. 褰撳墠id灏忎簬鍗囧簭涓嬬殑绗4鏉id;
銆銆2. 褰撳墠id澶т簬闄嶅簭涓嬬殑绗4鏉id;
銆銆3.褰撳墠id澶勪簬杩欎袱鑰呬箣闂淬
銆銆鍏堝緱鍒版暟鎹琛ㄧ殑鏈澶(maxid)鍜屾渶灏(minid) id:
銆銆select max(id) maxid from mytb;
銆銆select min(id) minid from mytb;
銆銆鐒跺悗鍦ㄧ▼搴忎腑浣跨敤鍒ゆ柇璇鍙ワ紝姣斿傚湪php涓锛
銆銆$num=$id+4;
銆銆$where=" order by id desc";
銆銆if($id<$maxid-4 && $id>$minid+4) $where="and id<$num order by id desc";
銆銆if( $id<$minid+4) $where="and id>$minid order by id asc";
銆銆$sql="select id,title from mytb where id !=$id $where limit 8 ";
銆銆閫氳繃涓婅堪鏂规硶鍙栧嚭鏉ョ殑鍊间細闅忕潃褰撳墠ID鐨勫彉鍖栬屽彉鍖栵紝鐗瑰埆鏄褰撲綘涓婁紶鏂囩珷鐨勬椂鍊欙紝濡傛灉鎶婄浉鍏虫х殑鏂囩珷绱ф尐鐫涓婁紶锛岄偅涔堢浉鍏虫у氨浼氭洿寮恒
銆銆褰撶劧锛屼篃鍙浠ヤ娇鐢ㄥ尮閰嶅叧閿璇嶇殑鏂瑰紡锛屼絾鏄涓绡囨枃绔犲線寰鏈夊ソ鍑犱釜鍏抽敭璇嶏紝浣曞喌鐩稿叧闃呰诲線寰鏄鍦ㄥ悓涓鏍忕洰涓嬭繘琛岀殑锛屾煡璇㈡晥鐜囪繙娌℃湁涓婇潰鎻愪緵鐨勬柟娉曞己銆
銆銆鐢卞ぇ鎴愮綉(http://http://www.zjjv.com//)鎻愪緵锛岃浆杞借锋敞鏄庡嚭澶勩