簡體   English   中英

從一個表中獲取ID字段(字段名稱相同)

[英]Get the ID field from one tables (field name is the same)

我現在正嘗試從我的供應商表中獲取ID字段。 字段名稱為ID。 我以為我可以只發送“vendor.id”我的SQL查詢,但它不斷拋出一個錯誤,不返回任何數據。

我認為問題是我的用戶表也有一個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但即時發現我需要它現在....這些小東西都是那么討厭它工作正常!

好消息是,我終於可以看到光明! 在這里謝謝大家幫助我與我的第一個web應用程序!

您的代碼產生含有請求`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');

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM