assign("SITE_NAME",SITE_NAME); $fobj = new FormObject("管理:アナウンス情報"); //------------------ //改ページ初期化 //------------------ $page = (int)"{$_GET['page']}"; if ($page == 0) { $page = 1; } $limit = 10; $offset = ($page -1) * $limit; $sql = " SELECT SQL_CALC_FOUND_ROWS m1.news_id, date_format(m1.disp_date,'%Y.%m.%d') as news_date, m1.note, m1.title, m1.news_cate, m1.img FROM ds_news m1 WHERE m1.del_flg = 0 ORDER BY m1.disp_date desc,news_id desc LIMIT {$limit} OFFSET {$offset} "; $sth = $dbMaster->prepare($sql); $result = $dbMaster->execute($sth,array()); //件数 $sql_num = "SELECT FOUND_ROWS()"; $result_num = $dbMaster->query($sql_num); if(DB::isError($result_num)){ print $sql; err_proc($result_num->getMessage()); } $all_num = 0; if($row_num = $result_num->fetchRow()){ $all_num = $row_num[0]; } $tmpl->assign("data_num",(int)$num); $tmpl->loopset("list1") ; while($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { $tmpl->assign("news_id",$row['news_id']); $tmpl->assign("news_date",$row['news_date']); $tmpl->assign("title",$row['title']); $tmpl->assign("news_cate",$fobj->getLabelValue("news_cate",$row['news_cate'])); $tmpl->loopnext(); } $tmpl->loopset("") ; //------------------------------- //新改ページリンク //------------------------------- $before_link = ""; $next_link = ""; $before_link_num = $page -1; $total_link = ceil($all_num / $limit); $before_link_num = $page - 1; $next_link_num = $total_link - $page; if ($before_link_num > 4) { $before_link_num = 4; if ($next_link_num < 4) { $before_link_num = 4 + (4 - $next_link_num); } } if ($next_link_num > 4) { $next_link_num = 4; if ($before_link_num < 4) { $next_link_num = 4 + (4 - $before_link_num); } } $first_target_no = 0; $td_num = 9-4; //左右のTD数 //戻るページリンク生成 for($x = 0; $x < $before_link_num; $x++) { $target_no = $page - $before_link_num + $x; if ($target_no < 1) { continue; } $s = (($target_no -1) * $limit) + 1; $e = $s + $limit - 1; //$before_link .= "{$s}-{$e} / "; $before_link .= "{$target_no}"; if ($x == 0) { $first_target_no = $target_no; } } if($first_target_no > 1){ $ddd = --$first_target_no; $before_link = "back" . $before_link; } //次へページリンク生成 $last_target_no = $page ; for($x = 0; $x < $next_link_num; $x++) { $target_no = $page + $x + 1; if((($target_no - 1)* $limit) < $all_num){ $last_target_no = $target_no; $s = (($target_no -1) * $limit) + 1; $e = $s + $limit - 1; if ($e > $all_num) { $e = $all_num; } //$next_link .= " / {$s}-{$e}"; $next_link .= "
{$target_no}
"; } else { break; } } if((($last_target_no)* $limit) < $all_num){ $ddd = ++$last_target_no; $next_link .= "next"; } //$next_link .="
"; $tmpl->assign("before_link",$before_link); $tmpl->assign("next_link",$next_link); $tmpl->assign("now_page",$page); if ($all_num > 0) { $tmpl->assign("now_link","{$page}"); $tmpl->assign("ok_result",1); } else { $tmpl->assign("now_link",""); $tmpl->assign("no_result",1); } $tmpl->flush(); ?>