Forum Moderators: coopster

Message Too Old, No Replies

Having a problem with case logic

         

Markbad311

10:04 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



I a m having troubkle with a certain CASE STATEMENT

$table_name2 = "bob_storys";
$sql2 ="SELECT CASE isnull(id)
WHEN 1 then 'Story (0)'
ELSE CASE rtrim(id)
WHEN '' then 'Story (0)'
ELSE CONCAT('<a href=http://www.example.com/battle_bands_sherlocks/band_battle_.php?story=',id,'>View story ()</a>')
END END id, band_name FROM $table_name2 WHERE $band_name = band";
$result2 = mysql_query($sql2, $connection) or die (mysql_error());
$num = mysql_num_rows($sql2, $connection) or die (mysql_error());
while ($row = mysql_fetch_array($result2)) {
$story = ($row['id']);

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Story = band' at line 6

<Sorry, no personal URLs.
See Terms of Service [webmasterworld.com]>

[edited by: tedster at 10:13 pm (utc) on Feb. 12, 2006]
[edit reason] use example.com [/edit]

zCat

10:28 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



You have "END END" in this line:
END END id, band_name FROM $table_name2 WHERE $band_name = band"; 

maybe that's it.

Edit: maybe not, I see you've nested the statements. Try writing the statement out in a more easily readable format, that makes it easier for you and others to spot mistakes.

zCat

10:32 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



WHERE $band_name = band

maybe this is the wrong way round? i.e. band = '$band_name'? ( You don't tell us where $band_name is coming from so I'm just guessing).

DrDoc

10:33 pm on Feb 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to put single quotes around the $band_name variable

Markbad311

1:17 pm on Feb 13, 2006 (gmt 0)

10+ Year Member



Thanks all I have got it all figured out, yes it was in the wrong order and yes it needed single quotes. But I sort of went with a differenct approach. Thanks for your help.

DrDoc

4:49 pm on Feb 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



order doesn't matter :)