2013-09-21 172 views
1

我現在試圖從我的供應商表中獲取ID字段。字段名稱是ID。我以爲我可以發送'vendor.id'給我的sql查詢,但它一直拋出一個錯誤,並沒有返回任何數據。從一個表中獲取ID字段(字段名稱相同)

我認爲問題是我的用戶表中也有一個ID字段。是否有發送到函數,而不是「vendor.id」

電話功能的請求一種特殊的方式(在到底是「vendor.id」,抓住並返回數據

$data2 = display_all_orders($limit, 'fName', 'lName', 'VendorName', 'DateRequested', 'Shipping', 'VendorNumber', 'VendorFax', 'VendorAddress', 'VendorCity', 'VendorState', 'VendorZip', 'EquipmentConsumable', 'GasType', 'GasLocation', 'UNMTag', 'EquipmentLocation', 'index', 'totalcost', 'Approved', 'Shipped', 'user_id', 'vendor.id'); 

功能:

function display_all_orders($limit) 
{ 
    $data = array(); 
    $limit = (int)$limit; 

     $func_num_args = func_num_args(); 
     $func_get_args = func_get_args(); 

// print_r($func_get_args); 
       if ($func_num_args > 1) 
         { 
           unset($func_get_args[0]); 



           $fields = '`' . implode('`, `', $func_get_args) . '`'; 


       $results = mysql_query("SELECT $fields FROM `users` , `vendor` WHERE users.id = vendor.user_id ORDER BY vendor.DateRequested DESC"); 
       for($x = 0; $x < $limit; $x++) 
       { 

       $data[] = mysql_fetch_assoc($results); 
       } 
       return $data; 
      } 

} 
?> 

,如果我不嘗試讓我現在就需要的vendor.id但即時發現工作得很好....這些小東西真討厭

好消息是,我能!終於看到了光!感謝大家在這裏幫助我用我的第一個webapp!

+0

可能愚蠢的問題:你說你的廠商表有一個字段:「ID」,但您的代碼使用「vender.id」 mysql是區分大小寫的 - 可以這樣簡單嗎?如果沒有,請發佈執行的確切查詢(只在mysql_query之前將其回顯出來)以及它給出的錯誤(mysql_error) –

+0

抱歉!沒有供應商表格是小寫。謝謝! – HELPMEPLEASE

+0

所以 - 請發佈確切的查詢和錯誤。 –

回答

2

你的代碼產生一個包含`vendor.id`這是一個錯誤的字段名稱的請求。

使用:

$data2 = display_all_orders($limit, 'fName', 'lName', 'VendorName', 'DateRequested', 'Shipping',  
    'VendorNumber', 'VendorFax', 'VendorAddress', 'VendorCity', 'VendorState', 'VendorZip', 
    'EquipmentConsumable', 'GasType', 'GasLocation', 'UNMTag', 'EquipmentLocation', 'index', 'totalcost', 
    'Approved', 'Shipped', 'user_id', 'vendor`.`id'); 

應該工作,但它是一個黑客..

+0

有趣,所以你需要從ID分離供應商...你爲什麼稱它爲黑客這是不是正確的方式做事情?我現在測試這個,並讓你知道它是否工作! – HELPMEPLEASE

+0

糾正它的工作原理!謝謝你的回答! – HELPMEPLEASE

+0

啊,這是一個很好的結果。它的黑客攻擊是因爲它「破解」你的內部功能。從技術上講,你不需要'' –

相關問題