VFPCGI Day2

出自VFP Wiki

跳轉到: 導航, 搜尋
VFPCGI的第二天

客人:來點肉吧~ 夥計:就來啦~

所以,放點肉吧~ 如果你會一點簡單的 html 語法的話,那麼你大概已經想到,可以怎麼顯示資料了。如果不太懂,那麼也沒關係,這裡會慢慢告訴你。

html 裡面要想畫表格的話,只要會三個 html tag:table、tr、td <table>與</table>代表的是表格,夾在中間的元素就是 tr 與 td 於是

<table>
<tr>
<td>
Hello world
</td>
</tr>
</table>

就會是一個格子。

把昨天的 cgi01.prg 複製成 cgi02.prg,然後將 cgi02.prg 設為主程式。 作一點修改,開啟 VFP 附贈的 Sample 資料庫,並且利用 TRY ... ENDTRY 來幫助我們除錯~

*
* cgi02
*
DECLARE INTEGER GetStdHandle in Win32API integer nHandleType
declare integer WriteFile    in Win32API integer hFile, string @ cBuffer,;
		integer nBytes, integer @ nBytes2, integer @ nBytes3

LOCAL lnOutHandle
LOCAL lnBytesWritten
LOCAL lnOverLappedIO 
LOCAL lcOutput
LOCAL lnCount

lnOutHandle=GetStdHandle(-11) 
lnBytesWritten=0
lnOverLappedIO=0
lcOutput = "HTTP/1.0 200 OK"+chr(13)+chr(10) + ;
	"Content-type: text/html"+chr(13)+chr(10) + ;
	CHR(13) + CHR(10)

SET EXCLUSIVE OFF 
SET TALK OFF 

TRY 
	OPEN DATABASE HOME(1) + "\Samples\Data\testdata"
	USE customer

	GO top
	lnCount = 0
	lcOutput = lcOutput + "<table border='1'>"
	SCAN
		lcOutput = lcOutput + "<tr>"
		lcOutput = lcOutput + "<td>"
		lcOutput = lcOutput + customer.contact
		lcOutput = lcOutput + "</td>"
		lcOutput = lcOutput + "<td>"
		lcOutput = lcOutput + customer.company
		lcOutput = lcOutput + "</td>"
		lcOutput = lcOutput + "</tr>"
		lnCount = lnCount + 1
		IF lnCount > 50 THEN  && 只顯示 50 筆
			EXIT 
		ENDIF
	ENDSCAN 
	lcOutput = lcOutput + "</table>"
CATCH TO oErr
	lcOutput = lcOutput + "<p>"
	lcOutput = lcOutput + "Error: " + oErr.Message
	lcOutput = lcOutput + "</p>"
FINALLY 
	CLOSE DATABASES ALL 
ENDTRY 

WriteFile(lnOutHandle, @lcOutput, len(lcOutput), @lnBytesWritten, @lnOverLappedIO)

編譯之後,還是跟昨天一樣,丟到 c:\inetpub\wwwroot\vfpcgi 下面 記得,確定 IIS 已經啟動之後,打開瀏覽器,在網址列輸入 http://localhost/vfpcgi/vfpcgi.exe

Yes~你已經看到今天的肉了。