早上好,新年快乐!
我正在尝试将MYSQL数据库中的所有记录选择为1列与列表匹配的数组,然后从该列中选择时替换单元格的输出。
这是一张运动表,我的位置为MF,DF,CF,并希望分别用Midfield,Defense和Forward替换它们。
我希望以下内容会破解它,但会收到一条错误消息,该消息会排到FROM行:
警告:mysql_fetch_assoc()要求参数1为资源,在/home/peterborough/www/www/wp-content/plugins/insert-php/insert_php.php(48)中给出布尔值:eval()'d code第14行
$result = mysql_query("SELECT *,
CASE Position
WHEN 'DF' THEN 'Defence'
WHEN 'MF' THEN 'Midfield'
WHEN 'CF' THEN 'Forward'
FROM People
WHERE
(Position='DF' or
Position='MF' or
Position='CF') and
Season = '2014'
ORDER BY Number");
while($row = mysql_fetch_assoc($result)){...}
谢谢你们
答案 0 :(得分:2)
您的SQL中存在语法错误:
CASE
表达式需要END
SELECT *,
CASE Position
WHEN 'DF' THEN 'Defence'
WHEN 'MF' THEN 'Midfield'
WHEN 'CF' THEN 'Forward'
END AS position_long
FROM People
WHERE
(Position='DF' or
Position='MF' or
Position='CF') and
Season = '2014'
ORDER BY Number
说明:
当语法错误发生时,您会从FALSE
调用中获得mysql_query()
当它被传递到mysql_fetch_assoc()
时抱怨给出布尔而不是资源