- Jul 09 Fri 2010 09:09
置頂常用連結
- Aug 26 Sun 2012 11:51
讀寫檔案
將讀寫改為實際檔案,再用讀檔的方式載入。
$file = fopen(FCPATH."/ajax/rand_list.json","w");
fputs($file,json_encode($list));
fclose($file);
$json = file_get_contents(FCPATH."/ajax/rand_list.json");
return $json;
- Aug 24 Fri 2012 13:24
codeigniter去index.php
config檔底下:
$config['index_page'] = '';
.htaccess檔內:
<IfModule mod_rewrite.c>
<Files ~ "^.(htaccess|htpasswd)$">
deny from all
</Files>
Options -Indexes
Options +FollowSymLinks
#允許解析文件中的SSI指令
Options +Includes
#定義404,500錯誤頁面
ErrorDocument 404 /404.htm
ErrorDocument 500 /404.htm
#定義目錄索引頁面
DirectoryIndex index.php
order deny,allow
RewriteEngine on
#設置根目錄
#RewriteBase /你的ci目錄/
#去掉鏈接地址中index.php字符串
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|flash|images|img|includes|js|public|language|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
- Jul 24 Tue 2012 20:12
Codeigniter系統開發佈署筆記(1)
基於久了又會忘記,趕快查一查記錄在此。
首先是Controller繼承。
置於application\core 底下
/* ---------------- 開始 ---------------- */
class BASE_Controller extends CI_Controller
{
function __construct() {
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library('form_validation');
/* 這是在模組用
$obj =& get_instance();
$obj->load->helper('url');
*/
}
function show_menu($ml, $url="", $css_id="nav") {
$base_url = $this->config->item('base_url');
$full_url = $this->config->item('full_url');
$menu_code = '<ul id="'.$css_id.'">';
foreach($ml AS $k => $v) {
$menu_code .= '<li>' . anchor($full_url.$url."/".$k,"$v") . '</li>';
}
$menu_code .= '</ul>';
return $menu_code;
}
abstract class Pages_Controller extends Base_Controller
{
}
abstract class Admin_Controller extends Base_Controller
{
}
/* ---------------- 結束 ---------------- */
基本上這樣就能夠分別在不同的頁面(一般頁及後台頁)給不同的繼承。
置於控制器部分,我的思維是每個頁面(function)只要做好基本設置,佈署很快
class Admin extends Admin_Controller {
function __construct() {
parent::__construct();
}
//控制器名稱
public $name = '管理端 ';
public $path = 'index.php/admin';
//管理區選單陣列
public $nav = array
(
'index' => '回前台',
'admin' => '首頁',
);
public function index()
{
//載入網站資訊
$data['web_info'] = $this->web_info();
$data['web_info']['page'] = $this->name .'首頁';
$data['web_info']['theme'] = 'v1';
//載入選單
$menu = $this->nav;
$data['menu'] = $this->show_menu($menu,$this->path);
$data['content'] = '首頁';
$this->load->view('admin',$data);
}
在view部分則用includes
<?php $this->load->view('includes/header'); ?>
內容
<?php $this->load->view('includes/footer'); ?>
即可。
- Feb 22 Wed 2012 23:09
jquery 紀錄
簡單來說我是要透過固定格式的網址,運用span(display:none)放參數去組合出連結。
然後運用css的方式製作按鈕,html會很乾淨,連結透過jquery產生,css製作美觀按鈕。
html
<dl>
<dt><a>點心</a></dt><span>01</span>
<dd class="four"> </dd>
<dd class="sea"> </dd>
</dl>
<dl>
<dt><a>點心試是<br />
試看試</a></dt><span>11</span>
<dd class="four">diamˋximˊ</dd>
<dd class="sea">diamˊsimˋ</dd>
</dl>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" language="javascript">
google.load("jquery", "1.6");
</script>
<script type="text/javascript">
$(function(){
var word_url = "upload/wma/talk/2011Dec/word/"; //單字路徑
var dialogue_url = "upload/wma/talk/2011Dec/dialogue/"; //對話路徑
var jsclick = "javascript:javascript:wav";
// 單字-四縣腔
$(".word .four").each(function (i) {
$(this).prepend( "<a href=\""
+ jsclick + "('" + word_url + "four/" +
$(this).parent().find("span").text() + ".wma')\" >" +
"</a>"
);
});
// 單字-海陸腔
$(".word .sea").each(function (i) {
$(this).prepend( "<a href=\""
+ jsclick + "('" + word_url + "sea/" +
$(this).parent().find("span").text() + ".wma')\" >" +
"</a>"
);
});
// 對話
$(".dialogue li").each(function (i) {
var num = $(this).find("span").text();
$(this).prepend(
"<a class=\"four\" href=\"" + jsclick + "('" + dialogue_url + "four/" + num + ".wma')\" >" + "</a>" +
"<a class=\"sea\" href=\"" + jsclick + "('" + dialogue_url + "sea/" + num + ".wma')\" >" + "</a>"
);
});
$(".word .four").click(function(){
alert($(this).prev().find("span").text());
});
});
</script>
- Dec 28 Wed 2011 14:07
自己弄的jQuery ajax查詢 - 整合jQuery pager
這不是一般常搜尋到的jquery pager,js貼在最後。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>網頁標題</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" language="javascript">
google.load("jquery", "1.5");
google.load("jqueryui", "1.5.2");
</script>
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.pager.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var pages_click;//用來傳遞
$("#per").change(function(){
ejajax();
})
$("input.os").blur(function(){
$("#dis_st").val(0);
$("#loading").stop();
//加入緩幾秒
ejajax();
})
PageClick = function(pageclickednumber) {
$("div.pager").pager({ pagenumber: pageclickednumber, pagecount: 15,
buttonClickCallback: PageClick});
pages_click = pageclickednumber;
ejajax("pages");
}
$("#sub").click(function(){
$("tr").remove(".db_list");
$("tr").remove(".s_list");
$("#dis_st").val(0);
ejajax();
})
$("input.2page").click(function(){
$("tr").remove(".db_list");
$("tr").remove(".s_list");
ejajax("to");
})
$("tr.s_list").hover(function(){
$("tr").remove(".db_list");
$("tr").remove(".s_list");
ejajax("to");
})
function ejajax(type){
$("tr").remove(".db_list");
$("tr").remove(".s_list");
var sSearch = $("#sSearch").val();
var sSearch_1 = $("#sSearch_1").val();
var sSearch_2 = $("#sSearch_2").val();
var sSearch_3 = $("#sSearch_3").val();
var sSearch_4 = $("#sSearch_4").val();
var sSearch_5 = $("#sSearch_5").val();
switch(type){
default:
var dis_st = (parseInt($("#dis_st").val())<=0)?0:parseInt($("#dis_st").val());
var data = {
"sSearch": sSearch,
"sSearch_1" : sSearch_1,
"sSearch_2" : sSearch_2,
"sSearch_3" : sSearch_3,
"sSearch_4" : sSearch_4,
"sSearch_5" : sSearch_5,
"dis_st" : $("#dis_st").val(),
"dis_len" : $("#per").val()
}
break;
case "to":
var a1 = $("#per").val();
var a2 = ($("input.goto").val()>parseInt($("a.total_page").text()))?parseInt($("a.total_page").text()):$("input.goto").val();
var dis_st = a1*a2-a1;
$("#dis_st").val(dis_st);
var data = {
"sSearch": sSearch,
"sSearch_1" : sSearch_1,
"sSearch_2" : sSearch_2,
"sSearch_3" : sSearch_3,
"sSearch_4" : sSearch_4,
"sSearch_5" : sSearch_5,
"dis_st" : dis_st,
"dis_len" : $("#per").val()
}
break;
case "pages":
$("#dis_st").val(dis_st);
var a1 = $("#per").val();
var a2 = (pages_click>parseInt($("a.total_page").text()))?parseInt($("a.total_page").text()):pages_click;
var dis_st = a1*a2-a1;
var data = {
"sSearch": sSearch,
"sSearch_1" : sSearch_1,
"sSearch_2" : sSearch_2,
"sSearch_3" : sSearch_3,
"sSearch_4" : sSearch_4,
"sSearch_5" : sSearch_5,
"dis_st" : dis_st,
"dis_len" : $("#per").val()
}
break;
};
$("#loading").fadeIn("slow");
$.ajax({
url: "ejquery-.php",
data:data,
type: "POST",
dataType: "json",
success: function(Ddata) {
var i = 0;
var total = Ddata["iTotalRecords"];
var total = Ddata["iTotalDisplayRecords"];
var aaData = Ddata["aaData"];
if (aaData != "") {
$.each(aaData, function() {
$("#show").append("<tr class=\"s_list\">" +
"<td class='num'>" + (i+1) + /*"-" + aaData[i][0] + */"</td>" +
"<td class='pt'> <a target=\"_blank\" href=\"" + aaData[i][4] + "\">" + aaData[i][1] + "</a></td>" +
"<td class='issn'>" + aaData[i][2] + "</td>" +
"<td class='eissn'>" + aaData[i][3] + "</td>" +
"<td class='range'>" + aaData[i][5] + "</td>" +
"</tr>");
i++;
});
}else{
var nodata = "No Articles Found";
$("#show").append("<tr class=\"s_list nodata\" align=\"center\">" +
"<td colspan=\"5\">" + nodata +"</td></tr>");
}
$("#dis_st").val(dis_st);
$("a.total").text(total);
var p = Math.ceil(total / $("#per").val());
var per = parseInt($("#per").val());
var st = parseInt($("#dis_st").val());
var page = Math.ceil(st / per)+1;
$("div.pager").pager({ pagenumber: page, pagecount: p, buttonClickCallback: PageClick });
$("a.total").text(total);
$("a.page").text(page);
$("a.total_page").text(p);
},
Error: function() {
alert("ERROR!!!");
}
});
$("#loading").ajaxStart(function(){
$(this).fadeIn("slow");}
).ajaxStop(function(){
$(this).fadeOut("slow");
});
$("div.status").fadeIn("slow");
}//end function
})
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("div.pager").pager({ pagenumber: 1, pagecount: 15, buttonClickCallback: PageClick });
});
PageClick = function(pageclickednumber) {
$("div.pager").pager({ pagenumber: pageclickednumber, pagecount: 15, buttonClickCallback: PageClick
});
}
</script>
<body>
<div id="wrap">
<div id="container">
<div id="header">
<h1></h1>
</div>
<div id="bar">
<div id="search_bar">
<input id="sSearch" name="sSearch" size="30" type="text" value="" />
<input id="sub" type="submit" name="Submit" value="送出" />
</div>
<div class="pager"></div>
<div class="status">
Page <a class="page"></a> of <a class="total_page"></a> | <a class="total"></a> Records.
GO to Page<input class="goto" name="goto" size="4" type="text" value="" /> <input class="2page" type="submit" name="2page" value="GO" />
<input name="post" size="10" type="hidden" value="" /></div>
</div>
<div id="content">
<div id="loading" style="display:none" ><img src="images/ajax-loader.gif" />Loading....</div>
<select name="select" id="per">
<option value="10">顯示10筆</option>
<option value="30">顯示30筆</option>
<option value="50">顯示50筆</option>
<option value="100">顯示100筆</option>
</select>
<br />
<table cellspacing="0" cellpadding="0" id="show">
<tr bgcolor="#FFE9C8" height="24">
<th></th>
<th style="text-align:left;"><input name="sSearch_1" type="text" class="os" id="sSearch_1" size="60"/> </th>
<th><input name="sSearch_2" type="text" class="os" id="sSearch_2" size="10"/> </th>
<th><input name="sSearch_3" type="text" class="os" id="sSearch_3" size="10"/> </th>
<th><input name="sSearch_5" type="text" id="sSearch_5" class="os"/></th></tr>
<tr bgcolor="#FFE9C8" height="24" class="title">
<th width="3%"> </th>
<th width="67%" style="text-align:left;">資料抬頭
<th width="10%">資料抬頭</th>
<th width="10%">資料抬頭</th>
<th width="10%">資料抬頭</th>
</tr>
</table>
<input name="tt_str" size="10" type="hidden" value="" />
<input name="dis_st" id="dis_st" size="10" type="hidden" value="0" />
<input name="key" size="10" type="hidden" value="" />
<div class="pager" ></div>
<div class="status">
Page <a class="page"></a> of <a class="total_page"></a> | <a class="total"></a> Records.
GO to Page<input class="goto" name="goto" size="4" type="text" value="" /> <input class="2page" type="submit" name="2page" value="GO" />
<input name="post" size="10" type="hidden" value="" /></div>
</div>
</div>
<div id="footer">
COPYRIGHT 2011
</div>
</div>
</div>
</body>
</html>
/*----------------下面jquery pager code-------------------*/
/*
* jQuery pager plugin
* Version 1.0 (12/22/2008)
* @requires jQuery v1.2.6 or later
*
* Example at: http://jonpauldavies.github.com/JQuery/Pager/PagerDemo.html
*
* Copyright (c) 2008-2009 Jon Paul Davies
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Read the related blog post and contact the author at http://www.j-dee.com/2008/12/22/jquery-pager-plugin/
*
* This version is far from perfect and doesn't manage it's own state, therefore contributions are more than welcome!
*
* Usage: .pager({ pagenumber: 1, pagecount: 15, buttonClickCallback: PagerClickTest });
*
* Where pagenumber is the visible page number
* pagecount is the total number of pages to display
* buttonClickCallback is the method to fire when a pager button is clicked.
*
* buttonClickCallback signiture is PagerClickTest = function(pageclickednumber)
* Where pageclickednumber is the number of the page clicked in the control.
*
* The included Pager.CSS file is a dependancy but can obviously tweaked to your wishes
* Tested in IE6 IE7 Firefox & Safari. Any browser strangeness, please report.
*/
(function($) {
$.fn.pager = function(options) {
var opts = $.extend({}, $.fn.pager.defaults, options);
return this.each(function() {
// empty out the destination element and then render out the pager with the supplied options
$(this).empty().append(renderpager(parseInt(options.pagenumber), parseInt(options.pagecount), options.buttonClickCallback));
// specify correct cursor activity
$('.pages li').mouseover(function() { document.body.style.cursor = "pointer"; }).mouseout(function() { document.body.style.cursor = "auto"; });
});
};
// render and return the pager with the supplied options
function renderpager(pagenumber, pagecount, buttonClickCallback) {
// setup $pager to hold render
var $pager = $('<ul class="pages"></ul>');
// add in the previous and next buttons
$pager.append(renderButton('first', pagenumber, pagecount, buttonClickCallback)).append(renderButton('prev', pagenumber, pagecount, buttonClickCallback));
// pager currently only handles 10 viewable pages ( could be easily parameterized, maybe in next version ) so handle edge cases
var startPoint = 1;
var endPoint = 9;
if (pagenumber > 4) {
startPoint = pagenumber - 4;
endPoint = pagenumber + 4;
}
if (endPoint > pagecount) {
startPoint = pagecount - 8;
endPoint = pagecount;
}
if (startPoint < 1) {
startPoint = 1;
}
// loop thru visible pages and render buttons
for (var page = startPoint; page <= endPoint; page++) {
var currentButton = $('<li class="page-number">' + (page) + '</li>');
page == pagenumber ? currentButton.addClass('pgCurrent') : currentButton.click(function() { buttonClickCallback(this.firstChild.data); });
currentButton.appendTo($pager);
}
// render in the next and last buttons before returning the whole rendered control back.
$pager.append(renderButton('next', pagenumber, pagecount, buttonClickCallback)).append(renderButton('last', pagenumber, pagecount, buttonClickCallback));
return $pager;
}
// renders and returns a 'specialized' button, ie 'next', 'previous' etc. rather than a page number button
function renderButton(buttonLabel, pagenumber, pagecount, buttonClickCallback) {
var $Button = $('<li class="pgNext">' + buttonLabel + '</li>');
var destPage = 1;
// work out destination page for required button type
switch (buttonLabel) {
case "first":
destPage = 1;
break;
case "prev":
destPage = pagenumber - 1;
break;
case "next":
destPage = pagenumber + 1;
break;
case "last":
destPage = pagecount;
break;
}
// disable and 'grey' out buttons if not needed.
if (buttonLabel == "first" || buttonLabel == "prev") {
pagenumber <= 1 ? $Button.addClass('pgEmpty') : $Button.click(function() { buttonClickCallback(destPage); });
}
else {
pagenumber >= pagecount ? $Button.addClass('pgEmpty') : $Button.click(function() { buttonClickCallback(destPage); });
}
return $Button;
}
// pager defaults. hardly worth bothering with in this case but used as placeholder for expansion in the next version
$.fn.pager.defaults = {
pagenumber: 1,
pagecount: 1
};
})(jQuery);
- Dec 26 Mon 2011 11:23
自己弄的jQuery ajax查詢 - PHP檔(回傳)
aColumns 就是資料庫欄位,此欄位順序對應到前台html區丟來的資料順序,所以必須跟sSearch對應。
此篇沒有使用排序功能,所以排序就沒差了。若要排序功能,則是在前台傳遞參數加上iSortCol_N的資料。
可以設定一組驗證值,否則無法直接觀看。放在一開始的if條件即可。
<?php
if(true){
//isset($_POST['ej']) or isset($_POST['post'])
/* 排除sql注入 */
foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); }
/*
*
* 識別字使用的慣用命名規則
*
* a – array
* b – boolean
* f – float
* fn – function
* i – integer
* n – node (表格的一個節點)
* o – object
* s – string
* aa - Array of Array
*
所需POST資料
dis_st => 設定列出初始值
dis_len => 設定列出範圍
iSortCol_N => 0為判定(isset)是否排序,其餘為欄位量
sSortCol_N => 欄位名稱
sSearch => 搜尋字串(全欄位)
bSearchable_N => 全欄位搜尋後的單欄位是否搜尋判斷
sSearchable_N => 單欄位搜尋值
*/
$aColumns = array( 'p_id','p_name','p_issn', 'p_eissn','p_link', 'p_range' );
$aColumns_title = array( '','名稱','ISSN', 'EISSN','連結', '範圍' );
//設定不出現
$aHidden = array(0,4);
if(isset($_POST['Sort'])){
for ($i=0; $i<Count($aColumns);$i++){
for($j=0; $j<Count($aHidden); $j++){
if($aHidden[$j]==$i){continue;};
if($_POST['Sort'][$i]!=""){
$sSortable[$i] = $_POST['Sort'][$i];
}
}
}
}
if(isset($_POST['Searchable'])){
for ($i=0; $i<Count($aColumns);$i++){
if($_POST['Searchable'][$i]!="" ){
$sSearchable[$i] = $_POST['Searchable'][$i];
}
}
}
//$_POST['dis_st'] = 30;
//$_POST['dis_len'] = 20;
$_POST['sSearch'] = isset($_POST['sSearch'])?$_POST['sSearch']:"";
$_POST['dis_st'] = isset($_POST['dis_st'])?$_POST['dis_st']:0;
/* 接受值轉換 */
$sql_option = array(
"dis_st" => $_POST['dis_st'],
"dis_len" => $_POST['dis_len'],
"iSortingCols" => Count($aColumns),
"sSearch" => $_POST['sSearch'],
);
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = $aColumns[0];
/* 資料庫資訊 */
$setSql['user'] = "root";
$setSql['password'] = "";
$setSql['db'] = "ej";
$setSql['server'] = "localhost";
/* 資料表 */
$sTable = "ej_periodical";
/*
* MySQL 連線
*/
$setSql['link'] = mysql_pconnect( $setSql['server'], $setSql['user'], $setSql['password'] ) or
die( '無法連線到伺服器' );
mysql_select_db( $setSql['db'], $setSql['link'] ) or
die( '無法選擇資料表 '. $setSql['db'] );
/*
* 頁數切換 dis_st起始 dis_len範圍
*/
$sLimit = "";
if ( isset( $sql_option['dis_st'] ) && $sql_option['dis_len'] != '-1' )
{
if($sql_option['dis_len'] !== 0){
$sLimit = "LIMIT ".mysql_real_escape_string( $sql_option['dis_st'] ).", ".
mysql_real_escape_string( $sql_option['dis_len'] );
}
}
/*
* Ordering 排序設定
*/
$sOrder = "";
if ( isset( $sql_option['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i<intval( $sql_option['iSortingCols'] ) ; $i++ )
{
if ( isset($_POST['iSortCol_'.$i]) && $_POST['iSortCol_'.$i]!="")
{
$sOrder .= $aColumns[ intval( $_POST['iSortCol_'.$i] ) ]."
".mysql_real_escape_string( $_POST['sSortDir_'.$i] ) .", ";
}
}
//替換後方兩字,也就是替換", "為"",若沒有排序則將ORDER BY取消
$sOrder = substr_replace( $sOrder, "", -2 );
if ( $sOrder == "ORDER BY" )
{
$sOrder = "";
}
}
/*
* Filtering 全資料搜尋功能(過濾)
*/
$sWhere = "";
if ( $sql_option['sSearch'] != "" or $sql_option['sSearch'] != null)
{
$sWhere = "WHERE (";
for ( $i=1 ; $i<count($aColumns) ; $i++ )//主鍵不搜尋
{
$sWhere .= $aColumns[$i]." LIKE '%".$sql_option['sSearch']."%' OR ";
}
//將最後三字元替換為"",也就是刪除"OR "
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
/*
* Individual column filtering 單欄資料搜尋功能(過濾)
*/
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ( isset($_POST['sSearch_'.$i]) && $_POST['sSearch_'.$i] != '' )
{
if ( $sWhere == "" )
{
$sWhere = "WHERE ";
}
else
{
$sWhere .= " AND ";
}
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_POST['sSearch_'.$i])."%' ";
}
}
/*
* SQL queries 執行SQL
* 取得資料傳至$rResult
*/
//這邊一樣是將最後一筆 , 拿掉,implode是將陣列組合為字串,str_replace是將符合的替換掉。
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable
$sWhere
$sOrder
$sLimit
";
$rResult = mysql_query( $sQuery, $setSql['link'] ) or die(mysql_error());
/* Data set length after filtering
* 設定在查詢(過濾)後的資料筆數
*/
$sQuery = "
SELECT FOUND_ROWS()
";
$rResultFilterTotal = mysql_query( $sQuery, $setSql['link'] ) or die(mysql_error());
$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
$iFilteredTotal = $aResultFilterTotal[0];
/* 資料總筆數 */
$sQuery = "
SELECT COUNT(".$sIndexColumn.")
FROM $sTable
";
$rResultTotal = mysql_query( $sQuery, $setSql['link'] ) or die(mysql_error());
$aResultTotal = mysql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];
/*
* 輸出
*/
$sOutput = '{';
$sOutput .= '"dis_st": '.$_POST['dis_st'].', ';
$sOutput .= '"dis_len": '.$_POST['dis_len'].', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ( $aColumns[$i] != ' ' )
{
/* General output */
$sOutput .= '"'.str_replace('"', '\"', $aRow[ $aColumns[$i] ]).'",';
}
}
/*
* Optional Configuration:
* If you need to add any extra columns (add/edit/delete etc) to the table, that aren't in the
* database - you can do it here
*/
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';
echo $sOutput;
}else{
echo "此頁面不能直接訪問!";
}
?>
- Dec 26 Mon 2011 11:11
自己弄的jQuery ajax查詢 - HTML檔(查詢區)
ejajax就是觸發ajax的函數,所以上面無論是change、click、以及keyup都是用選擇符指定哪個物件透過什麼動作觸發ejajax的函式。
change用在下拉選單,而keyup或keydown就是在搜尋欄位每輸入一個字就觸發。
sSearch則是全欄位搜尋,其餘sSearch_1~ 5則是自訂多少欄位可以單獨搜尋。
而資料倒出則透過 $.each(aaData, function() 這函式進行組合。
最後決定輸出什麼資料就是在該區將json的資料篩出後組合出html。
當然也可以使用get傳遞,要改成get傳遞就是在組合送出的位址,那每次行為改變網址即可。
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" language="javascript">
google.load("jquery", "1.4");
google.load("jqueryui", "1.5.2");
</script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("#per").change(function(){
ejajax();
})
$("input.os").keyup(function(){
ejajax();
})
$("a#first").click(
function () {
ejajax("first");
}
)
$("a#last").click(
function () {
ejajax("last");
}
)
$("a#next").click(
function () {
ejajax("+");
}
)
$("a#prev").click(
function () {
ejajax("-");
}
)
$("#sub").click(function(){
$("tr").remove(".db_list");
$("tr").remove(".s_list");
ejajax();
})
$("#2page").click(function(){
$("tr").remove(".db_list");
$("tr").remove(".s_list");
ejajax("to");
})
function ejajax(type){
$("tr").remove(".db_list");
$("tr").remove(".s_list");
var sSearch = $("#sSearch").val();
var sSearch_1 = $("#sSearch_1").val();
var sSearch_2 = $("#sSearch_2").val();
var sSearch_3 = $("#sSearch_3").val();
var sSearch_4 = $("#sSearch_4").val();
var sSearch_5 = $("#sSearch_5").val();
switch(type){
default:
var dis_st = (parseInt($("#dis_st").val())<=0)?0:parseInt($("#dis_st").val());
var data = {
"sSearch": sSearch,
"sSearch_1" : sSearch_1,
"sSearch_2" : sSearch_2,
"sSearch_3" : sSearch_3,
"sSearch_4" : sSearch_4,
"sSearch_5" : sSearch_5,
"dis_st" : $("#dis_st").val(),
"dis_len" : $("#per").val()
}
break;
case "+":
//大為總數為總數
var dis_st = (parseInt($("#dis_st").val()) + parseInt($("#per").val())>$("#total").text())?parseInt($("#dis_st").val()):parseInt($("#dis_st").val()) + parseInt($("#per").val());
var data = {
"sSearch": sSearch,
"sSearch_1" : sSearch_1,
"sSearch_2" : sSearch_2,
"sSearch_3" : sSearch_3,
"sSearch_4" : sSearch_4,
"sSearch_5" : sSearch_5,
"dis_st" : dis_st,
"dis_len" : $("#per").val()
}
break;
case "-":
//小於0仍為0
var dis_st = ((parseInt($("#dis_st").val()) - parseInt($("#per").val()))<0)?0:parseInt($("#dis_st").val()) - parseInt($("#per").val());
var data = {
"sSearch": sSearch,
"sSearch_1" : sSearch_1,
"sSearch_2" : sSearch_2,
"sSearch_3" : sSearch_3,
"sSearch_4" : sSearch_4,
"sSearch_5" : sSearch_5,
"dis_st" : dis_st,
"dis_len" : $("#per").val()
}
break;
case "first":
//小於0仍為0
var dis_st = 0;
var data = {
"sSearch": sSearch,
"sSearch_1" : sSearch_1,
"sSearch_2" : sSearch_2,
"sSearch_3" : sSearch_3,
"sSearch_4" : sSearch_4,
"sSearch_5" : sSearch_5,
"dis_st" : dis_st,
"dis_len" : $("#per").val()
}
break;
case "last":
//小於0仍為0
var a1 = parseInt($("#total_page").text());
var a2 = $("#per").val();
var dis_st = (a1*a2)-a2;
var data = {
"sSearch": sSearch,
"sSearch_1" : sSearch_1,
"sSearch_2" : sSearch_2,
"sSearch_3" : sSearch_3,
"sSearch_4" : sSearch_4,
"sSearch_5" : sSearch_5,
"dis_st" : dis_st,
"dis_len" : $("#per").val()
}
break;
case "to":
var a1 = $("#per").val();
var a2 = ($("#goto").val()>parseInt($("#total_page").text()))?parseInt($("#total_page").text()):$("#goto").val();
var dis_st = a1*a2-a1;
$("#dis_st").val(dis_st);
var data = {
"sSearch": sSearch,
"sSearch_1" : sSearch_1,
"sSearch_2" : sSearch_2,
"sSearch_3" : sSearch_3,
"sSearch_4" : sSearch_4,
"sSearch_5" : sSearch_5,
"dis_st" : dis_st,
"dis_len" : $("#per").val()
}
break;
};
$("#loading").fadeIn("slow");
$.ajax({
url: "ejquery.php",
data:data,
type: "POST",
dataType: "json",
success: function(Ddata) {
var i = 0;
var total = Ddata["iTotalRecords"];
var total = Ddata["iTotalDisplayRecords"];
var aaData = Ddata["aaData"];
$.each(aaData, function() {
$("#test").append("<tr class=\"s_list\">" +
"<td>" + (i+1) + "-" + aaData[i][0] + "</td>" +
"<td> <a target=\"_blank\" href=\"" + aaData[i][4] + "\">" + aaData[i][1] + "</a></td>" +
"<td>" + aaData[i][2] + "</td>" +
"<td>" + aaData[i][3] + "</td>" +
"<td>" + aaData[i][5] + "</td>" +
"</tr>");
i++;
});
$("#dis_st").val(dis_st);
$("#total").text(total);
var p = Math.ceil(total / $("#per").val());
var per = parseInt($("#per").val());
var st = parseInt($("#dis_st").val());
var page = Math.ceil(st / per)+1;
$("#total").text(total);
$("#page").text(page);
$("#total_page").text(p);
},
Error: function() {
alert("ERROR!!!");
}
});
$("#loading").ajaxStart(function(){
$(this).fadeIn("slow");}
).ajaxStop(function(){
$(this).fadeOut("slow");
});
}//end function
})
</script>
<body>
<p> </p>
<div id="loading" style="display:none" >載入中....</div>
<table cellspacing="0" cellpadding="0" id="test">
<tr bgcolor="#FFE9C8" height="24">
<td><select name="select" id="per">
<option value="10">顯示10筆</option>
<option value="30">顯示30筆</option>
<option value="50">顯示50筆</option>
<option value="100">顯示100筆</option>
</select></td>
<td><input name="sSearch_1" type="text" id="sSearch_1" class="os"/></td>
<td><input name="sSearch_2" type="text" id="sSearch_2" class="os"/></td>
<td><input name="sSearch_3" type="text" id="sSearch_3" class="os"/></td>
<td><input name="sSearch_5" type="text" id="sSearch_5" class="os"/></td>
</tr>
<tr bgcolor="#FFE9C8" height="24">
<td width="10%">欄位一</td>
<td width="40%">欄位二</td>
<td width="20%">欄位三</td>
<td width="20%">欄位四</td>
<td width="10%">欄位五</td>
</tr>
<tr bgcolor="#FFFFFF" height="24">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<input id="sSearch" name="sSearch" size="30" type="text" value="" />
<input id="sub" type="submit" name="Submit" value="送出" />
<tr bgcolor="#FFFFFF" height="24">
<td colspan="5">查無資料!</td>
</tr>
</table>
<input name="tt_str" size="10" type="hidden" value="" />
<input name="dis_st" id="dis_st" size="10" type="hidden" value="0" />
<a id="first" href="#">最前頁</a>|
<a id="prev" href="#">上一頁</a>|
<a id="next" href="#">下一頁</a>|
<a id="last" href="#">最後一頁</a>,目前在第<a id="page" href="#"></a>頁/共<a id="total_page" href="#"></a>頁,總筆數:<a id="total"></a>
前往<input id="goto" name="goto" size="2" type="text" value="" /> 頁 <input id="2page" type="submit" name="2page" value="前往" />
<input name="post" size="10" type="hidden" value="" />
- Dec 19 Mon 2011 22:58
codeigniter extend
2.1版在core下建立MY_Controller.php檔案
內容為:
/*-------------------------------------*/
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class FUN_Controller extends CI_Controller{
public $site = array(
"name" => "網站名稱",
"tag" => "標籤"
);
public function __construct()
{
parent::__construct();
}
function FUN_Controller () {
parent::Controller();
}
}
/*-------------------------------------*/
Controller繼承
/*-------------------------------------*/
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Front extends FUN_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
echo $this->site['name']; //呼叫變數(全域)
$this->load->view('Front',$data);
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/Front.php */
/*-------------------------------------*/
- Nov 27 Sun 2011 17:02
Codeiginter Session登入登出 控制器、模組、視圖試作
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Model {
/*
* 調用方式
*
*
########## Controllers 控制器各頁面 ##########
if (!$this->session->userdata("admin")) redirect("member/login");
########## Controllers 控制器部份 ##########
public function login()
{
//檢查session值
//echo $this->session->userdata("admin");
//echo $this->session->userdata("uid");
$data["path_name"] = "登入頁";
$data['base_url'] = $this->config->item('base_url');
$data['this_url'] = $data['base_url'] . "index.php/member/login";
$check = array(
'bl' => false,
'msg' => ''
);
if(isset($_POST['login']))
{
$logid = $this->input->post('login_id'); //對應view的表單
$logpwd = $this->input->post('login_pwd');
$this->load->model('Login');
$check = $this->Login->check($logid,$logpwd);//回傳參數bl(布林),以及msg 何種錯誤訊息
if ($check['bl']){
$newdata = array( //寫入session的參數
'uid' => $logid,
'admin' => TRUE, //必須對應驗證
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
redirect("member"); //成功後轉向
}
}
$data['login_msg']= $check['msg'] ;
$this->load->view('view_login',$data);
}
//登出
public function logout()
{
$del_session = array('uid', 'admin', 'logged_in');
$this->load->model('Login');
$this->Login->logout($del_session);
redirect('member/login');
}
########## Views 視圖部份 ##########
<?php echo form_open_multipart('member/login');?>
<label>
帳號
<input type="text" name="login_id" id="login_id" />
</label>
<br />
<label>
密碼
<input type="password" name="login_pwd" id="login_pwd" />
</label>
<input type="hidden" name="login" value="1" id="login" />
<br />
<label>
<input type="submit" name="button" id="button" value="登入" />
</label>
</form>
<a href="logout">登出</a>
*
*
*/
function __construct()
{
parent::__construct();
$this->load->database();
}
function check($id,$pwd)
{
//讀取資料庫字串
//$query = $this->db->get('check_db');
$key = "@lib";
$msg[0] = "登入成功";
$msg[1] = "查無此帳號";
$msg[2] = "請重新檢查帳號密碼";
$msg[3] = "無法進行認證";
if (true)//$query->num_rows() > 0)
{
//$check = $query->result_array();
$check[0]['id'] = "abc";
$check[0]['pwd'] = "ecfc8084e7c6c29e3ccf3f202635a197";
$check[1]['id'] = "def";
$check[1]['pwd'] = "d3bb34166864b20243936820ef8c5935";
$check[2]['id'] = "user";
$check[2]['pwd'] = "user001";
$i = 1;
foreach ($check as $row)
{
if($id!=$row['id'])
{
$check['msg'] = $msg[1];
$check['bl'] = false;
continue;// 檢查帳號,不是就跳出此次循環
}else{
$mdpwd = md5($pwd.$key);
if($mdpwd == $row['pwd'])
{
//驗證成功
$check['msg'] = $msg[0];
$check['id'] = $id;
//$check['level'] = "可以添加權限回傳";
$check['bl'] = true;
}else{
echo "出錯訊息:" . $mdpwd ."<br/>";
$check['msg'] = $msg[2];
$check['bl'] = false;
}
break;//檢測密碼,帳號對了就不再跑迴圈
}
}
return $check;
}else{
$check['msg'] = $msg[3];
$check['bl'] = false;
return $check;
}
}
function logout($del_session)
{
foreach ($del_session as $row)
{
$this->session->unset_userdata($row);
}
}
}
/* End of file login.php */
/* Location: ./application/Model/login.php */