Jump to content

[SOLVED] Switch Statement (It's not as easy as '1', '2', '3', '4')


Chezshire

Recommended Posts

Hello Everyone,

 

I'm learning PHP via self teaching and I'm attempting my first 'Switch' statement, and i've hit a huge snag in my page falls completely apart with an annoying error message when I attempt to utilize the switch statement. So i'm looking for help and guidance from all the smart people ;)

 

My goal it to make each character display in accordance with there squad. So 1, 2, 3, or 4 will equal 'Alpha'.

 

help  :-[

 

This is a URL of what I'm trying to affect

http://www.xpg.us/institute/institute1.2.php

 

This is a URL of what happens when I try to add the switch statment

http://www.xpg.us/institute/institute1.3.php

 

 

This is my error message:

Parse error: parse error, unexpected T_STRING in /home/content/z/a/n/zanland/html/xpg/institute/institute1.3.php on line 60

 

This is line 60

	switch ($i) {

 

This is the full code:

<?php
	//title
	echo "<br>\n<h2><font color='#A5B9D5'>TRAINING SQUADRONS</font></h2>\n";	

	//get characters by squadron
	$sql = "SELECT id, squadronDB, codename FROM cerebra ORDER BY squadronDB";
	$result = mysql_query($sql) or trigger_error(mysql_error,E_USER_ERROR);
	while($row = mysql_fetch_assoc($result)){
	//here's the key. Use a while loop to repeat through the code

	$thisID = $codename["id"];
	$squadronDB = getSquad($thisID);	

	$squadronDB = getChar($char_ID);

	switch ($i) {
case "1":
    echo "i is Alpha";
    break;
case "2":
    echo "i is Alpha";
    break;
case "3":
    echo "i is Alpha";
    break;
case "4":
    echo "i is Alpha";
    break;

	// start character div
	echo '<div style="float: left; padding-top: 5; width: 220;">';
	echo "<span class='fineprint'>";


	// makes thin bar
	echo '<hr align="centered" color="#050F1D" size="2" width="66%">';

	// image div
	echo '<div style="float: left; padding-left: 5;"><img src="/cerebra/images/'.$row['id'].'-.jpg" width="60" height="75" border="2px" bordercolor="#415582"></div>';

	// name div
	// styles
	echo '<div style="float: left; vertical-align: top; padding-left: 5;"><p>';
	// span and model name
	echo '<span class="fineprint"><i>'.$row['squadronDB'];
	// link and codename
	echo ' <br>as <a href="/cerebra/display.php?id='.$row['id'].'">'.$row['codename'].'</a></i></span></p></div>';


	// end character div
	echo '</div>';

	//these two lines (or any lines up to the closing brace) will be repeated for each row returned by the query
	}

	?>

 

 

 

 

Link to comment
Share on other sites

<?php
//title
echo "<br>\n<h2><font color='#A5B9D5'>TRAINING SQUADRONS</font></h2>\n";	

//get characters by squadron
$sql = "SELECT id, squadronDB, codename FROM cerebra ORDER BY squadronDB";
$result = mysql_query($sql) or trigger_error(mysql_error,E_USER_ERROR);
while($row = mysql_fetch_assoc($result)){
//here's the key. Use a while loop to repeat through the code

$thisID = $codename["id"];
$squadronDB = getSquad($thisID);	

$squadronDB = getChar($char_ID);

switch ($i) {
	case "1":
		echo "i is Alpha";
		break;
	case "2":
		echo "i is Alpha";
		break;
	case "3":
		echo "i is Alpha";
		break;
	case "4":
		echo "i is Alpha";
		break;

// start character div
echo '<div style="float: left; padding-top: 5; width: 220;">';
echo "<span class='fineprint'>";


// makes thin bar
echo '<hr align="centered" color="#050F1D" size="2" width="66%">';

// image div
echo '<div style="float: left; padding-left: 5;"><img src="/cerebra/images/'.$row['id'].'-.jpg" width="60" height="75" border="2px" bordercolor="#415582"></div>';

// name div
// styles
echo '<div style="float: left; vertical-align: top; padding-left: 5;"><p>';
// span and model name
echo '<span class="fineprint"><i>'.$row['squadronDB'];
// link and codename
echo ' <br>as <a href="/cerebra/display.php?id='.$row['id'].'">'.$row['codename'].'</a></i></span></p></div>';


// end character div
echo '</div>';

//these two lines (or any lines up to the closing brace) will be repeated for each row returned by the query
}
} // You forgot to close your while.
?>

Link to comment
Share on other sites

Thank you TempleKMDKrazd and Thank you Unidox,

 

I closed the statement as you suggested, but now i get a 'Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/z/a/n/zanland/html/xpg/institute/institute1.4.php on line 47' The code works when the switch statement isn't present so i'm sure it's a result of the switch... Ouchie wow wah?

 

This is line 47:

echo "<br>\n<h2><font color='#A5B9D5'>TRAINING SQUADRONS</font></h2>\n";	

 

 

PHP code which is sick and needs doctoring:

<TD width='124' align='center'><p><a href='/images/XPGmanhattan.jpg' title="Download a map of Manhattan's amazing sites and sounds!"><img src="/images/XPGmanhattan_sm.jpg" alt="Brochure" width="124" height="250" border="0"><span class='fineprint'>See Manhattan</span></a> 
</TR>
<TR>
	<TD COLSPAN="3" align="left">

	<?php
//title
echo "<br>\n<h2><font color='#A5B9D5'>TRAINING SQUADRONS</font></h2>\n";	

//get characters by squadron
$sql = "SELECT id, squadronDB, codename FROM cerebra ORDER BY squadronDB";
$result = mysql_query($sql) or trigger_error(mysql_error,E_USER_ERROR);
while($row = mysql_fetch_assoc($result)){
//here's the key. Use a while loop to repeat through the code

$thisID = $codename["id"];
$squadronDB = getSquad($thisID);	

$squadronDB = getChar($char_ID);

switch ($i) {
	case "1":
		echo "i is Alpha";
		break;
	case "2":
		echo "i is Alpha";
		break;
	case "3":
		echo "i is Alpha";
		break;
	case "4":
		echo "i is Alpha";
		break;

// start character div
echo '<div style="float: left; padding-top: 5; width: 220;">';
echo "<span class='fineprint'>";


// makes thin bar
echo '<hr align="centered" color="#050F1D" size="2" width="66%">';

// image div
echo '<div style="float: left; padding-left: 5;"><img src="/cerebra/images/'.$row['id'].'-.jpg" width="60" height="75" border="2px" bordercolor="#415582"></div>';

// name div
// styles
echo '<div style="float: left; vertical-align: top; padding-left: 5;"><p>';
// span and model name
echo '<span class="fineprint"><i>'.$row['squadronDB'];
// link and codename
echo ' <br>as <a href="/cerebra/display.php?id='.$row['id'].'">'.$row['codename'].'</a></i></span></p></div>';


// end character div
echo '</div>';

//these two lines (or any lines up to the closing brace) will be repeated for each row returned by the query
}
} // You forgot to close your while.
?>

	</TD>
</TR>
</TABLE>
</DIV>

 

Link to comment
Share on other sites

I've been looking at my code trying to figure out why the T-String error was happening, and I figured it out, I had some pollution in the code; When I copied the example of how to 'close' the php, some of the spaces had an odd 'formating' to them. (I figured out the format issue by turning on the 'see invisibles' in textWrangler which is what i use to code with.

 

So I've gotten to step one. I've hit a new roadblock relating to this but shall post that up as I think it counts as a new issue, rather then as the same issue. Thank you to those who helped me!

Chez

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.