Posted on: 11/22/03 05:43pm
By: Anonymous (Whoosh)
I'm pretty new to PHP and need help. Can someone help me with this code?
I am trying to put some PHP code in header.thtml. If the user is logged in, I want to display a LOGOUT graphic in the header (and when the mouse goes over it I want the logout graphic to change). But if the user is logged out, I want a LOGIN graphic to display in the header (and when the mouse goes over it I want the login graphic to change).
Here is something like what I want, but I need the stuff between the if/else statements converted to PHP syntax.
<?php
if ($_USER['uid'] > 1) {
<td colspan=2> <a href="{site_url}/users.php?mode=logout"
onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('logoutover','','{layout_url}/images/logoutover.gif',1)">
<img name="logoutoff" src="{layout_url}/images/logoutoff.gif" width=48 height=29 border=0></a></td>
} else {
<td colspan=2> <a href="{site_url}/users.php?mode=login"
onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('loginover','','{layout_url}/images/loginover.gif',1)">
<img name="loginoff" src="{layout_url}/images/loginoff.gif" width=48 height=29 border=0></a></td>
}
?>
Is this even possible to do? Thanks for any help in understanding it. I've tried everything I know to do.
Re:Will someone help with a PHP header.thtml issue?
Posted on: 11/22/03 05:55pm
By: Dirk
Did you see
this thread[*1] ? You will have to use "print".
bye, Dirk
Re:Will someone help with a PHP header.thtml issue?
Posted on: 11/22/03 08:13pm
By: Anonymous (Whoosh)
Hi Dirk:
I saw this thread. But you see I don't want to simply print the words. I want to display graphics that say login or logout.
Do I still need to use print? I'll try this and see what happens. Apologies for such dumb questions.
Re:Will someone help with a PHP header.thtml issue?
Posted on: 11/22/03 09:32pm
By: Blaine
You need to use the php command echo or print since your new HTML is inside the PHP tags. Just entering HTML is not valid PHP.
This example is:
echo "<td>This is a <b>table</b> row</td>";
Re:Will someone help with a PHP header.thtml issue?
Posted on: 11/22/03 11:41pm
By: Anonymous (Whoosh)
I think I understand. Thanks a lot Blaine. So it seems that when you use print or echo in this case, you are in a sense printing the html (conditionally) into the header.thtml script to be executed. I hope my understanding here is correct. I'll go buy a PHP book and stop asking such basic things here.
Re:Will someone help with a PHP header.thtml issue?
Posted on: 11/22/03 11:55pm
By: Blaine
That is correct. Just adding the echo or print with quotes should do it. You need to be carefull using single and double quotes. You need to quote the complete line you want to string that you want to echo but you will likely have quotes as well in that string.
So as an example. Use single quotes on the outside and double quotes on the inside.
echo '<a href="http://www.google.com">google</a>';
Alternatively you will see people escape the quotes so they are not interpreted by PHP as in:
echo "<a href=\"http://www.google.com\">google</a>";
Hopefully that helps.
Re:Will someone help with a PHP header.thtml issue?
Posted on: 11/23/03 01:02am
By: Anonymous (Whoosh)
Ah. Yes. Thanks so much. I also see that this can be tricky for the unitiated (like me ) when dealing with variables. Single quotes don't seem to alllow variable contents to display. Doubles do. So I am trying to follow the example I sometimes see in the GL code '(stuff here) "' . VARIABLE . '"(more stuff)'. That can get to be a bit maddening when dealing with long strings that contain variables.
Hey. This mini tutorial was really nice of you! It helps quite a lot.
Thanks!
Re:Will someone help with a PHP header.thtml issue?
Posted on: 11/23/03 07:34am
By: Anonymous (Whoosh)
Been all night at this. Need sleep. I have managed to take this:
<b><html>
<td colspan=2><a href="{site_url}/users.php?mode=logout" onMouseOut="MM_swapImgRestore()" </html></b>
and successfully translate it into this:
<b><?php
print '<td colspan=2><a href="' . $_CONF['site_url'] . '/users.php?mode=logout" onMouseOut="MM_swapImgRestore()"';
?></b>
That was easy because an example already existed of it. My problem is in trying to convert the following html lines into PHP:
<b>onMouseOver="MM_swapImage('buttonON','','{button_path}/ButtonON.gif',1)">
<img name="buttonON" src="{button_path}/button.gif" width=48 height=29 border=0></a></td></b>
I can probably do the "img name" line, but the "onMouseOver" command above has taken everything out of me. Is it even possible to do it?
{button_path} is really {layout_path}.
Thanks for any help - from anyone...