EExcel 丞燕快速查詢2

EExcel 丞燕快速查詢2
EExcel 丞燕快速查詢2 https://sandk.ffbizs.com/

php news records previous next

http://www.sitepoint.com/forums/showthread.php?645467-Retreiving-the-previous-and-next-row-through-PDO&p=4425809&viewfull=1#post4425809


SELECT
i.images_id
,COALESCE(
(SELECT images.images_id FROM images WHERE images.images_id < i.images_id ORDER BY images.images_id DESC LIMIT 1),
(SELECT images.images_id FROM images ORDER BY images.images_id DESC LIMIT 1)
) AS previous_images_id
,COALESCE(
(SELECT images.images_id FROM images WHERE images.images_id > i.images_id ORDER BY images.images_id ASC LIMIT 1),
(SELECT images.images_id FROM images ORDER BY images.images_id ASC LIMIT 1)
) AS next_images_id
FROM
images i
WHERE
i.images_id = 1



==========
for record, not for page

1、 get all new_id in array  (PDO fetchAll(PDO::FETCH_ASSOC) )

$all_news_ids = $crud->sql("select news_id from news");


2、get $now_news_id key for array

$now_news_id_key_id = array_search(array('news_id'=>$now_news_id), $ar_all_news_ids);


3、check $now_news_id_key_id first, if empty

$prive_news_id = empty($now_news_id_key_id)?"":get_record_column('news_id', $all_news_ids, $now_news_id_key_id+1);
$next_news_id = empty($now_news_id_key_id)?"":get_record_column('news_id', $all_news_ids, $now_news_id_key_id-1);



function get_array_column($val, $ar){
return array_key_exists($val, $ar)?$ar[$val]:"";
  }

function get_record_column($val, $ar, $rec_arrow=0){
return (isset($ar[$rec_arrow]))?get_array_column($val, $ar[$rec_arrow]) : "";
  }