簡體   English   中英

簡單查詢問題,where子句

[英]Simple query issue, where clause

我正在嘗試查詢工作! 我在這里有這個查詢:

$data = mysql_query( "SELECT date, time,location,type_of_payment,
        basket_information, user_id FROM retailer")

我也有這個變量:

$getuser[0]['user_id']

我需要設置一個子句,但是在編寫查詢的方式上遇到困難。 有人可以幫我編輯嗎?

$data = mysql_query( "SELECT date, time,location,type_of_payment,
        basket_information, user_id FROM retailer 
        WHERE user_id = $getuser[0]['user_id']")

謝謝..

$data = mysql_query( "SELECT date, time,location,type_of_payment,
                      basket_information, user_id FROM retailer 
                      WHERE user_id=".$getuser[0]['user_id'])

並且,您應該真正使用PDOmysqli代替mysql

您正在遇到PHP分析器故障:

$data = mysql_query( "SELECT [..snip..]  WHERE user_id=$getuser[0]['user_id']")

您試圖在使用帶引號的數組鍵(標記2)時將多維數組(標記1)插入雙引號字符串中。 PHP的解析器並不貪婪,因此不會“看到” ['user_id']作為數組引用的一部分。 這就是為什么有{}的原因。 另外,用雙引號引起來的字符串引用數組引用中的鍵會產生警告,因此...嘗試以下操作:

$data = "....... WHERE user_id={$getuser[0]['user_id']}")
                               ^---                   ^---

在執行代碼之前,您無法讀取SQL代碼中的數組,您可以這樣做:

$user = $getuser[0]['user_id'];
$data = mysql_query( "SELECT date, time,location,type_of_payment,
                      basket_information, user_id FROM retailer 
                      WHERE user_id = $user");

暫無
暫無

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

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