PHP MYSQL 数组中的 CASE 替换
PHP MYSQL CASE substitution in array
大家早上好,新年快乐!
我正在尝试 select 将 MYSQL 数据库中的所有记录放入一个数组中,其中 1 列与列表相匹配,然后在从 selected 时替换单元格的输出那一栏。
这是一个运动表,我的位置是MF、DF、CF,想分别替换为Midfield、Defence、Forward。
我希望下面的代码能破解它,但收到一条错误消息,该消息与 FROM 行对齐:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/peterborough/www/www/wp-content/plugins/insert-php/insert_php.php(48) : eval()’d code on line 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)){...}
谢谢大家
您的 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
说明:
当出现语法错误时,您会从 mysql_query()
调用中得到一个 FALSE
并且
当它被传递到 mysql_fetch_assoc()
it 抱怨被给予 boolean 而不是 resource
大家早上好,新年快乐!
我正在尝试 select 将 MYSQL 数据库中的所有记录放入一个数组中,其中 1 列与列表相匹配,然后在从 selected 时替换单元格的输出那一栏。
这是一个运动表,我的位置是MF、DF、CF,想分别替换为Midfield、Defence、Forward。
我希望下面的代码能破解它,但收到一条错误消息,该消息与 FROM 行对齐:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/peterborough/www/www/wp-content/plugins/insert-php/insert_php.php(48) : eval()’d code on line 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)){...}
谢谢大家
您的 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
说明:
当出现语法错误时,您会从 mysql_query()
调用中得到一个 FALSE
并且
当它被传递到 mysql_fetch_assoc()
it 抱怨被给予 boolean 而不是 resource