4 replies [Last post]
co2
co2's picture
Offline
Leader
UK
Last seen: 12 years 24 weeks ago
UK
Joined: 2003-09-17
Posts: 721
Points: 0

Hi All

I'm using a PHP switch routine to choose which text is used on a page, depending on which link is pressed prior to the page opening (the link passes the case number via the URL).

It works well, except, it echos/prints the case name of the text after the text also!

So:

	$txt=$_GET[txt];
switch ($txt) {
	case "1" :
		echo "Test1.";
	break;
	case "2" :
		echo "Test2.";
	break;
	case "3" :
		echo "Test3.";
	break;
	}

Then further down the page in the html:

<p><?php echo $txt ?></p>

This will result in something like this being displayed on the page:

Test1.

1

So the case number 1 is being displayed! :?

I understand (perhaps) why it's doing it, but, being a PHP person only when necessary, my knowledge of a fix is limited (or, time better spent elsewhere!)

Any ideas?

Smile

The next sentence is true. The previous sentence is false. Discuss...

Tags:
co2
co2's picture
Offline
Leader
UK
Last seen: 12 years 24 weeks ago
UK
Joined: 2003-09-17
Posts: 721
Points: 0

PHP Switch help

Okay, case solved... I put the switch PHP statement in the wrong place. It needed to be located actually where it was going to print the results in the page (as opposed to before the HTML).

Case dismissed. =D>

The next sentence is true. The previous sentence is false. Discuss...

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 37 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

PHP Switch help

As I only started to try and understand the "switch" routine yesterday,
am so glad you managed to solve it Smile
But of course I've now got to go over it again as your questions made me realise I am less than ofay with it :roll:

Ta!

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

co2
co2's picture
Offline
Leader
UK
Last seen: 12 years 24 weeks ago
UK
Joined: 2003-09-17
Posts: 721
Points: 0

PHP Switch help

I was never at ease with it until I actually had something to use it for... then the jigsaw sorta fitted together.

Smile

The next sentence is true. The previous sentence is false. Discuss...

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 37 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

PHP Switch help

This is often the problem, I find I'm trying to understand something whilst not actualy using it in a practical example; never works, as you say you need to be actually using it then the penny drops :roll:

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me