Forum Moderators: coopster

Message Too Old, No Replies

says "unexpected T STRING" tho' the previous lines are using the same

Switch statement being rejected in mid-definition?

         

DebW

3:05 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



I want to use the Switch statement to convert my query output to different selections in a menu of interpage links. I am using code syntax found in an online text, because I am clueless when it comes to this scripting. Can anyone help me understand why at line 84 (marked in "[]" in the code segment below), it "chokes" with an "unexpected T-String" error?

Thanks in advance to the helpful responder!

DebW
Code segment:

$query = "SELECT DISTINCT `Category` FROM `Contacts` WHERE `Category` NOT IN ('Individual Member', 'Group Member', 'Visitor Source', 'Trail Project', 'Restoration Project', 'Event Project', 'Other', '') AND `PriSt` = '$State' AND `Stop` = '$Stop' ORDER BY `Category` ASC";
$result = mysql_query($query)
or die ("No Visitors' Services Found.");

while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$Category = $row["Category"];
switch ($Category) {
case $Category = Accommodation:
echo ("<a href=\"#Sleep\"> Accommodations</a><br/>");
break;
case $Category = Activity:
echo ("<a href=\"#Do\">Recreation</a><br/>");
break;
case $Category = Attraction:
echo ("<a href=\"#See\"> Attractions</a> <br/>");
break;
case $Category = Business:
echo ("<a href=\"#Busi\"> Businesses</a><br/>");
break;
case $Category = Food/Beverage:
echo ("<a href=\"#Eat\"> Food Services</a> <br/>");
break;
case $Category = Service - General:
echo ("<a href=\"#Srvs\"> General Services</a><br/>");
break;
[Line 84:] case $Category = Health Service:
echo ("<a href=\"#Health\"> Health Services</a><br/>");
break;
case $Category = Official:
echo ("<a href=\"#Gov\"> Officials</a><br/>");
break;
case $Category = Shopping:
echo ("<a href=\"#Shop\"> Shopping</a><br/>");
break;
case $Category = Link Only:
echo ("<a href=\"#Lnks\"> Links</a>");
break;
default:
echo ("Sorry, TMRT has no Visitors' Services on record for this Stop.");
}

Psychopsia

3:23 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



Hi!

The Switch conditions should be:

switch ($Category) {
case 'Accommodation':
echo ("<a href=\"#Sleep\"> Accommodations</a><br/>");
break;
case 'Activity':

Hope this helps.

[edited by: Psychopsia at 3:23 pm (utc) on Sep. 28, 2006]

DebW

3:53 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



It worked! That's the second time you've saved me, Psychopsia -- thank you SO MUCH! :)