header("HTTP/1.0 404 Not Found");
exit;
2008年10月1日 星期三
強迫不要使用cache
欲讓使用者每次都能得到最新的資料,強迫不要使用快取(cache)
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") ."GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") ."GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
php寫下載excel
可以用Pear套件,下面是比較簡單的方式...
<input type="button" name="B1" value="下載EXCEL" onclick="location.href=download.xls">
\t:指Tab鍵(換欄位)
\n:指換行
$txtFile = "欄位A\t欄位B\t欄位C\t欄位D\n";
while ($row = mssql_fetch_array($result)){
$txtFile .= "'$row['id']\n"; //在值的前面加上單引號變成字串
}
//開啟EXCEL檔
//若檔案存在,則刪除檔案
if (file_exists("/localhost/download.xls")){
unlink("/localhost/download.xls");
}
if (!$file = fopen("/localhost/download.xls","w+")){
echo 開啟文字檔失敗
exit;
}
fputs($file,$txtFile); //把資料寫入檔案
fclose($file);
PS.若內容四個空格,會被當成tab鍵,所以…需把它替換掉
str_replace(' ',"",$result[$tab])
<input type="button" name="B1" value="下載EXCEL" onclick="location.href=download.xls">
\t:指Tab鍵(換欄位)
\n:指換行
$txtFile = "欄位A\t欄位B\t欄位C\t欄位D\n";
while ($row = mssql_fetch_array($result)){
$txtFile .= "'$row['id']\n"; //在值的前面加上單引號變成字串
}
//開啟EXCEL檔
//若檔案存在,則刪除檔案
if (file_exists("/localhost/download.xls")){
unlink("/localhost/download.xls");
}
if (!$file = fopen("/localhost/download.xls","w+")){
echo 開啟文字檔失敗
exit;
}
fputs($file,$txtFile); //把資料寫入檔案
fclose($file);
PS.若內容四個空格,會被當成tab鍵,所以…需把它替換掉
str_replace(' ',"",$result[$tab])
javascript 截取字串
String.substr(s,e) :從指定的位置(s)取指定長度(e)的字串。
String.substring(s,e) :從指定的位置(s)到指定的位置(e)的字串。
起始位置從0開始
code = 'abcdefghi'
function checkData(){
//計算字串的長度
var i = document.getElementById('code').value.length;
alert(i); // 9
//從指定位置2,到指定位置4的字串
var j = document.getElementById('code').value.substring(2,4);
alert(j); // cd
//從指定位置2,截取長度4的字串
var k = document.getElementById('code').value.substr(2,4);
alert(k); // cdef
}
String.substring(s,e) :從指定的位置(s)到指定的位置(e)的字串。
起始位置從0開始
code = 'abcdefghi'
function checkData(){
//計算字串的長度
var i = document.getElementById('code').value.length;
alert(i); // 9
//從指定位置2,到指定位置4的字串
var j = document.getElementById('code').value.substring(2,4);
alert(j); // cd
//從指定位置2,截取長度4的字串
var k = document.getElementById('code').value.substr(2,4);
alert(k); // cdef
}
2008年9月25日 星期四
把「開啟這類檔案之前,一定要先問我」回覆
把開啟這類檔案之前,一定要先問我的checkbox取消,想要再叫回…
到檔案總管的「資料夾選項」設定,將該檔案類型設定中的「下載後開檔時確認」勾起即可。
看你當初是下載哪一類型的檔案,就去恢復那一類型檔案的訊息,依此類推。
以 zip 檔案為例(修改其他檔案類型請依此類推):
- 開啟檔案總管,到「工具」>>「資料夾選項」(某些作業系統,如 Windows 98 是「檢視」>>「資料夾選項」)。
- 到「檔案類型」頁。
- 在「註冊的檔案類型」清單中,找到「WinZip File」,按「進階」(註一),勾「下載後進行開啟確認」,按確定,結束資料夾選項視窗。
2008年9月22日 星期一
PHP呼叫MSSQL的SP
$sql="Declare @OrderCode varchar(9),
@RetStr varchar(1000)
EXEC InsertPresentOrder 'START', @OrderCode OUT, @RetStr OUT
Select @OrderCode,@RetStr";
@RetStr varchar(1000)
EXEC InsertPresentOrder 'START', @OrderCode OUT, @RetStr OUT
Select @OrderCode,@RetStr";
$query=mssql_query($sql);
$OrderCode=mssql_result($query,0,0);
$RetStr=mssql_result($query,0,1);
php 呼叫sybase 的sp
sp:
CREATE PROCEDURE dbo.sp_u_test_test
@mult1 int, @mult2 int, @result int output
AS
BEGIN
select @result = @mult1 * @mult2
END
php:
$sql="declare @guess int
select @guess = 0
execute databse..sp_u_test_test 5, 6,
@result = @guess output";
$query=sybase_query($sql);
echo sybase_result($query,0,0);
==>30
參考資料:http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug/@Generic__BookTextView/43833;pt=42621/*
CREATE PROCEDURE dbo.sp_u_test_test
@mult1 int, @mult2 int, @result int output
AS
BEGIN
select @result = @mult1 * @mult2
END
php:
$sql="declare @guess int
select @guess = 0
execute databse..sp_u_test_test 5, 6,
@result = @guess output";
$query=sybase_query($sql);
echo sybase_result($query,0,0);
==>30
參考資料:http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug/@Generic__BookTextView/43833;pt=42621/*
2008年4月2日 星期三
找出資料表的欄位型態、大小、描述…等
找出table_name這個table的欄位名稱、型態(大小)、預設值、描述、isNull
Select C.COLUMN_NAME,
CASE DATA_TYPE WHEN 'nvarchar' THEN DATA_TYPE+'('+CONVERT(NVARCHAR(1000),CHARACTER_MAXIMUM_LENGTH)+')' ELSE DATA_TYPE END,
ISNULL(C.COLUMN_DEFAULT, ''), ISNULL(D.value, ''), CASE C.IS_NULLABLE WHEN 'NO' THEN '' ELSE 'Y' END,
D.NAME, D.object_id, D.minor_id,
C.DATA_TYPE, C.CHARACTER_MAXIMUM_LENGTH
From (
Select A.name, A.object_id, B.minor_id, B.value
From sys.tables A LEFT JOIN sys.extended_properties B
on A.object_id = B.major_id
) D RIGHT JOIN Information_Schema.Columns C
ON D.name = C.TABLE_NAME AND D.minor_id = C.ORDINAL_POSITION
Where C.TABLE_NAME = 'table_name'
ORDER BY C.ORDINAL_POSITION
Select C.COLUMN_NAME,
CASE DATA_TYPE WHEN 'nvarchar' THEN DATA_TYPE+'('+CONVERT(NVARCHAR(1000),CHARACTER_MAXIMUM_LENGTH)+')' ELSE DATA_TYPE END,
ISNULL(C.COLUMN_DEFAULT, ''), ISNULL(D.value, ''), CASE C.IS_NULLABLE WHEN 'NO' THEN '' ELSE 'Y' END,
D.NAME, D.object_id, D.minor_id,
C.DATA_TYPE, C.CHARACTER_MAXIMUM_LENGTH
From (
Select A.name, A.object_id, B.minor_id, B.value
From sys.tables A LEFT JOIN sys.extended_properties B
on A.object_id = B.major_id
) D RIGHT JOIN Information_Schema.Columns C
ON D.name = C.TABLE_NAME AND D.minor_id = C.ORDINAL_POSITION
Where C.TABLE_NAME = 'table_name'
ORDER BY C.ORDINAL_POSITION
2008年2月23日 星期六
脫逸資料庫語法中的特殊字元
mysql_real_escape_string -- 脫逸資料庫語法中的特殊字元.
脫逸資料庫語法中的特殊字元. 所以他可以安全放進mysql_query()執行.
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$item = "Zak's and Derick's Laptop";
$escaped_item = mysql_real_escape_string($item);
printf ("Escaped string: %s\n", $escaped_item);
?>
Escaped string: Zak\'s and Derick\'s Laptop
注: mysql_real_escape_string() 不脫逸 % 和 _.
See also: mysql_escape_string(), mysql_character_set_name().
資料來源:http://pda.php5.idv.tw/modules.php?mod=books&act=show&shid=477
脫逸資料庫語法中的特殊字元. 所以他可以安全放進mysql_query()執行.
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$item = "Zak's and Derick's Laptop";
$escaped_item = mysql_real_escape_string($item);
printf ("Escaped string: %s\n", $escaped_item);
?>
Escaped string: Zak\'s and Derick\'s Laptop
注: mysql_real_escape_string() 不脫逸 % 和 _.
See also: mysql_escape_string(), mysql_character_set_name().
資料來源:http://pda.php5.idv.tw/modules.php?mod=books&act=show&shid=477
字串加入斜線
AddSlashes
本函式使需要讓資料庫處理的字串,引號的部份加上斜線,以供資料庫查詢 (query) 能順利運作。這些會被改的字元包括單引號 (')、雙引號 (")、反斜線 backslash (\) 以及空字元 NUL (the null byte)。
語法: string addslashes(string str);
資料來源:http://stock.ettoday.com/book/function.php-AddSlashes.htm
本函式使需要讓資料庫處理的字串,引號的部份加上斜線,以供資料庫查詢 (query) 能順利運作。這些會被改的字元包括單引號 (')、雙引號 (")、反斜線 backslash (\) 以及空字元 NUL (the null byte)。
語法: string addslashes(string str);
資料來源:http://stock.ettoday.com/book/function.php-AddSlashes.htm
訂閱:
文章 (Atom)