Jump to content


Bad Switch statement


5 replies to this topic

#1 Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 16 May 2007 - 01:56 PM

I get an error which is:

Quote

Parse error: syntax error, unexpected T_LNUMBER, expecting T_CASE or T_DEFAULT or '}' in /home/faktionb/public_html/Admin/convert.php on line 6

The only things in convert.php are switch statements... Here is the code thats in convert.php. (line 6 is 01: in the first switch statement)
<?php
$month = $row['month'];
$day = $row['day'];

switch ($month) {
	01:
		$month == "January";
		break;
	02:
		$month == "February";
		break;
	03:
		$month == "March";
		break;
	04:
		$month == "April";
		break;
	05:
		$month == "May";
		break;
	06:
		$month == "June";
		break;
	07:
		$month == "July";
		break;
	08:
		$month == "August";
		break;
	09:
		$month == "September";
		break;
	10:
		$month == "October";
		break;
	11:
		$month == "November";
		break;
	12:
		$month == "December";
		break;
}
?>

I have tried everything I can think of. Even going to brute force with a crap load of if/else statements. Thanks to anyone who helps me out.

#2 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 16 May 2007 - 02:05 PM

You forgot the "case" keyword before you 01, 02 etc etc.

i.e...
switch ($month) {
case 01:

And so on.

Matt

#3 Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 16 May 2007 - 02:27 PM

lol... ya....


thanks...

#4 Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 16 May 2007 - 02:33 PM

mk well do you know why it isnt switching them? this is the code that is supposed to switch the month and day (just renaming) then display the new output.
while($row = mysql_fetch_array($query)) {
	include("convert.php");
	echo "
		<tr class=TourDates> 
		  <td valign=top>".$month." ".$day.", ".$row['year']." @ ".$row['time']."</td>
		  <td valign=top>".$row['city']."</td>
		  <td valign=top>".$row['venue']."</td>
		  <td>";
	echo nl2br($row['info']); 
	echo "</td>
		</tr>
		<tr>
		  <td colspan=4>
			<hr size=1>
		  </td>
		</tr>";
  }

It isn't changing anything at all... just leaving it the original 01-12 01-31.. anyone know this one?

#5 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 16 May 2007 - 04:16 PM

you could just make an array variable out of it.

$month = array(
   1 => "January",
   2 => "February",
   3 => "March",
   4 => "April",
   ...
   12 => "December"
);

then you can just access it by:
echo $month[5];
to output May.



but it isn't working because you're not actually changing the value of the variable $month

change this
case 01: $month == "January"; break;

to this
case 01: $month = "January"; break;

the first one you are just comparing the value in $month to the text "January"

Edited by SpatialVisionary, 16 May 2007 - 04:28 PM.


#6 Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 16 May 2007 - 04:56 PM

Thanks it works like a charm. Ya I thought about an array but for some reason I always build a more "bulky" piece of code, then after I get that working I turn it into an array. I will probably change it to an array in a few hours.

Close this topic please, it has been solved.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users