Re: [請益] php 撈資料庫的問題

看板PHP作者 (omg)時間16年前 (2010/01/28 23:34), 編輯推噓6(606)
留言12則, 4人參與, 最新討論串5/5 (看更多)
不好意思. 小弟是新手 在跑的時候 $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

01/28 23:35, , 1F
get_datatable不是就是一個function嗎??
01/28 23:35, 1F

01/28 23:35, , 2F
幹嘛要多打一個function???
01/28 23:35, 2F

01/29 00:41, , 3F
因為上一篇有打 function ...
01/29 00:41, 3F

01/29 10:20, , 4F
抱歉我筆誤了。
01/29 10:20, 4F

01/29 10:25, , 5F
因為我在提取字串函式時並沒有放進主程式測試。
01/29 10:25, 5F

01/29 10:25, , 6F
不過物件和使用函式則是測試過功能正常的。
01/29 10:25, 6F

01/29 10:35, , 7F
不過也因為這樣我就順便提到一個觀念:
01/29 10:35, 7F

01/29 10:35, , 8F
打錯字,會有解譯器幫你測出結果。
01/29 10:35, 8F

01/29 10:36, , 9F
邏輯錯誤,如果無法有效的做測試驗證,那可能會發生明知道
01/29 10:36, 9F

01/29 10:36, , 10F
有錯卻無法DEBUG的窘境。
01/29 10:36, 10F

01/29 10:46, , 11F
少加;
01/29 10:46, 11F

01/29 10:53, , 12F
那就加回去………
01/29 10:53, 12F
文章代碼(AID): #1BOQvmnn (PHP)
文章代碼(AID): #1BOQvmnn (PHP)