[英]Simple query issue, where clause
I am trying to get a query work! 我正在尝试查询工作! I have this query right here:
我在这里有这个查询:
$data = mysql_query( "SELECT date, time,location,type_of_payment,
basket_information, user_id FROM retailer")
I have this variable also: 我也有这个变量:
$getuser[0]['user_id']
I need to set a clause, but i have difficulties in the way of writing the query. 我需要设置一个子句,但是在编写查询的方式上遇到困难。 Can someone help me editing it please?
有人可以帮我编辑吗?
$data = mysql_query( "SELECT date, time,location,type_of_payment,
basket_information, user_id FROM retailer
WHERE user_id = $getuser[0]['user_id']")
Thanks.. 谢谢..
You're running into a PHP parser glitch: 您正在遇到PHP分析器故障:
$data = mysql_query( "SELECT [..snip..] WHERE user_id=$getuser[0]['user_id']")
you're trying to insert a multidimensional array (strike #1) into a double-quoted string, while using quoted array keys (strike #2). 您试图在使用带引号的数组键(标记2)时将多维数组(标记1)插入双引号字符串中。 PHP's parser isn't greedy, and will not "see" the
['user_id']
as part of the array reference. PHP的解析器并不贪婪,因此不会“看到”
['user_id']
作为数组引用的一部分。 That's why there's {}
. 这就是为什么有
{}
的原因。 Plus, quoting keys in array references in double-quoted strings will produce a warning, so... try this instead: 另外,用双引号引起来的字符串引用数组引用中的键会产生警告,因此...尝试以下操作:
$data = "....... WHERE user_id={$getuser[0]['user_id']}")
^--- ^---
You can't read an array in the SQL code, before you execute the code you could do: 在执行代码之前,您无法读取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.