PHP and if commands

Associate
Joined
13 Nov 2003
Posts
1,567
Location
Manchester
Hi All

Just working on something, trying to get an if command to work

What I need is a statement that I can drop into the body of my page that does the following things.

If $auth =1 then display some html
if $auth =0 then display nothing.

Im sure this is really easy but im still learning php lol

Thanks in advance you lovely people

:)
 
Code:
if ($auth == 1) {
//do stuff
} elseif ($auth == 2) {
//do other stuff
}
:)

One = (=) is the assignment operator, and two = (==) is the comparison operator :)
 
Spot on, cheers dude.

Now, this is slightly annoying im sure lol... but how do I put html within that, probably a table.

As I know html within php is a bit wierd lol

Thanks
Aaron
 
fluiduk said:
As I know html within php is a bit wierd lol
No it's not :p

You can either echo it:
Code:
<?php

if ($auth == 1)
{
    echo '<table>';
    echo '    <tr>';
    echo '        <td>text</td>';
    echo '        <td>text</td>';
    echo '        <td>text</td>';
    echo '    </tr>';
    echo '    <tr>';
    echo '        <td>text</td>';
    echo '        <td>text</td>';
    echo '        <td>text</td>';
    echo '    </tr>';
    echo '    <tr>';
    echo '        <td>text</td>';
    echo '        <td>text</td>';
    echo '        <td>text</td>';
    echo '    </tr>';
    echo '</table>';
}

?>

...or you can embed it:

Code:
<?php

if ($auth == 1)
{
?>
<table>
    <tr>
        <td>text</td>
        <td>text</td>
        <td>text</td>
    </tr>
    <tr>
        <td>text</td>
        <td>text</td>
        <td>text</td>
    </tr>
    <tr>
        <td>text</td>
        <td>text</td>
        <td>text</td>
    </tr>
</table>
<?php
}

?>
 
or heredoc:
Code:
echo <<<LOL
		<div class="64">
			<p>When I get older</p>
			<p>loosing my hair</p>
			<p>many years from now..</p>
		</div>
LOL;
 
Dj_Jestar said:
or heredoc:
Code:
echo <<<LOL
		<div class="64">
			<p>When I get older</p>
			<p>loosing my hair</p>
			<p>many years from now..</p>
		</div>
LOL;

I like heredoc apart from the fact that the end bit can't be indented, which kind of messes things up if you're a couple of blocks indented.

I find it really nice for generating RSS though, since you can populate some variables at the top and then heredoc the rest :cool:
 
Back
Top Bottom