作者godispower (omg)
看板PHP
標題Re: [請益] php 撈資料庫的問題
時間Thu Jan 28 23:34:06 2010
不好意思. 小弟是新手 在跑的時候
$datatable .= function get_datatable($row["id"],$row["item"]
,$row["barcode"],$row["datearrivetom"])
老是出現錯誤
寫著
Parse error: parse error, unexpected T_FUNCTION in /usr/file/web/management/development/whquery.php on line 21
※ 引述《tkdmaf (皮皮快跑)》之銘言:
: 整個方法重新改寫結構(是還可以再更加優美,不過先做到這樣好了。)
: 主程式檔名:whquery.php
: <?php
: require("sql_connect.php"); //連結資料庫程式檔,請自行實作他。
: require("class.data_serach.php");
: $data_serach = new data_serach("資料庫名稱","資料表名稱",3);
: //3表示要3個欄位才行,依實際需求來改
: $sql = $data_serach->sql_text();
: if (!empty($sql)){
: $result = mysql_query($sql,$conn);
: while($row = mysql_fetch_array($result))
: {
: $datatable .= function get_datatable($row["id"],$row["item"]
: ,$row["barcode"],$row["datearrivetom"])
: }
: echo $datatable;
: }else{
: echo "輸入資料不足,無法查詢";
: }
: mysql_free_result($result);
: mysql_close();
: fucntion get_datatable($id,$item,$barcode,$datearrivetom){
: $html = "<tr><td align='left' height='20'>$id</td>";
: $html .= "<td align='left'>$item</td>";
: $html .= "<td align='left'>$barcode</td>";
: $html .= "<td align='left'>$dataarrivetom</td></tr>";
: return $html;
: }
: ?>
: 檔名:class.data_serach.php
: 物件功能:
: 1.比對輸入欄位及資料庫欄位
: 2.輸入資料的欄位大於預設數量才進行查詢。
: 使用方法:
: $data_serach = new data_serach("資料庫名稱","資料表名稱",最小填入資料量);
: <?php
: class data_serach{
: function __construct($database,$table,$mixtimer){
: $this->database = $database;
: $this->table = $table;
: $this->mixtimer = $mixtimer;
: $this->load_field();
: $this->post_check();
: }
: function load_field(){
: $result = mysql_list_fields($this->database,$this->table);
: $field_num = mysql_num_fields($result);
: for ($i = 0;$i <$field_num;$i++){
: $fieldarr[] = mysql_field_name($result,$i);
: }
: $this->fieldarr = $fieldarr;
: }
: function post_check(){
: foreach($this->fieldarr as $value){
: if (strlen($_POST[$value]) != 0){
: $this->where .= "{$value}='{$_POST[$value]}' AND ";
: $this->timer +=1;
: }
: }
: }
: function sql_text(){
: if (($this->timer >= $this->mixtimer))
: return "SELECT * FROM incoming WHERE ".substr($this->where,0,-5);
: }
: }
: ?>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 201.100.13.140
推 EragonJ:get_datatable不是就是一個function嗎?? 01/28 23:35
→ EragonJ:幹嘛要多打一個function??? 01/28 23:35
→ chrisQQ:因為上一篇有打 function ... 01/29 00:41
推 tkdmaf:抱歉我筆誤了。 01/29 10:20
推 tkdmaf:因為我在提取字串函式時並沒有放進主程式測試。 01/29 10:25
→ tkdmaf:不過物件和使用函式則是測試過功能正常的。 01/29 10:25
推 tkdmaf:不過也因為這樣我就順便提到一個觀念: 01/29 10:35
→ tkdmaf:打錯字,會有解譯器幫你測出結果。 01/29 10:35
→ tkdmaf:邏輯錯誤,如果無法有效的做測試驗證,那可能會發生明知道 01/29 10:36
→ tkdmaf:有錯卻無法DEBUG的窘境。 01/29 10:36
推 anniehuang:少加; 01/29 10:46
推 tkdmaf:那就加回去……… 01/29 10:53