Hi all
The following code works fine to show text but I have blocks of html that I want to show instead of the text strings at present.
I have 5 tables that I want to output according to url parameter class. Echo doesn;t seem to work. How can I do this? Thanks
<?php
if ( urlencode($_GET['class']) == '1' ) {
echo "1 selected";
}
if ( urlencode($_GET['class']) == '2' ) {
echo "2 selected";
}
if ( urlencode($_GET['class']) == '3' ) {
echo "3 selected";
}
if ( urlencode($_GET['class']) == '4' ) {
echo "4 selected";
}
if ( urlencode($_GET['class']) == '5' ) {
echo "5 selected";
}
else {
}
?>
You need to remember to close off any php (with ?>) before you have any HTML code.
After each
if ( urlencode($_GET['class']) == 'X' ) {
line you need to add ?> on the next line. This tells PHP to stop processing, and just spit out the HTML as-is.
Hmm it doesn’t like this code
<?php
if ( urlencode($_GET['class']) == '1' ) {
?>
<p>Class #1!</p>
<?php
} //This ends the class == 1 if statement
if ( urlencode($_GET['class']) == '2' ) {
<p>Class #2!</p>
<?php
} //This ends the class == 2 if statement
if ( urlencode($_GET['class']) == '3' ) {
<p>Class #3!</p>
<?php
} //This ends the class == 3 if statement
if ( urlencode($_GET['class']) == '4' ) {
<p>Class #4!</p>
<?php
} //This ends the class == 4 if statement
if ( urlencode($_GET['class']) == '5' ) {
<p>Class #5!</p>
<?php
}
else {
?>
<p><strong>No Class!</strong></p>
<?php
}
?>
Just make sure you close off each if statement before opening the next one…
i.e. change
<?php
if ( urlencode($_GET['class']) == '2' ) {
to
<?php
} //This ends the class == 1 if statement
if ( urlencode($_GET['class']) == '2' ) {
P.S. If you use [ PHP ] instead of [ CODE ] on the forum it makes it much easier to read
Thanks for the reply Rob I got your example working but how do I do it for all the options- this code doesn’t show anything? Cheers
<?php
if ( urlencode($_GET['class']) == '1' ) {
?>
<p>Class #1!</p>
<?php
elseif ( urlencode($_GET['class']) == '2' ) {
?>
<p>Class #2!</p>
<?php
elseif ( urlencode($_GET['class']) == '3' ) {
?>
<p>Class #3!</p>
<?php
elseif ( urlencode($_GET['class']) == '4' ) {
?>
<p>Class #4!</p>
<?php
elseif ( urlencode($_GET['class']) == '5' ) {
?>
<p>Class #5!</p>
<?php
}
else {
?>
<p><strong>No Class!</strong></p>
<?php
}
?>
Bayliss_Trevor:
Hi all
The following code works fine to show text but I have blocks of html that I want to show instead of the text strings at present.
I have 5 tables that I want to output according to url parameter class. Echo doesn;t seem to work. How can I do this? Thanks
<?php
if ( urlencode($_GET['class']) == '1' ) {
echo "1 selected";
}
if ( urlencode($_GET['class']) == '2' ) {
echo "2 selected";
}
if ( urlencode($_GET['class']) == '3' ) {
echo "3 selected";
}
if ( urlencode($_GET['class']) == '4' ) {
echo "4 selected";
}
if ( urlencode($_GET['class']) == '5' ) {
echo "5 selected";
}
else {
}
?>
<?php
if ( urlencode($_GET['class']) == '1' ) {
?>
<p>Class #1!</p>
<?php
}
else {
?>
<p><strong>No Class!</strong></p>
<?php
}
?>