Re: [請益] php 撈資料庫的問題
不好意思. 小弟是新手 在跑的時候
$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
01/28 23:35, 1F
→
01/28 23:35, , 2F
01/28 23:35, 2F
→
01/29 00:41, , 3F
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
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
討論串 (同標題文章)
PHP 近期熱門文章
PTT數位生活區 即時熱門文章