MyBB Community Forums

Full Version: php if statements
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi guys,

I am trying to get some php working on my new community.

I have installed the PHP Conditions Plugin and it works, however, my code isn't. I want multiple conditions, but i cannot seem to get them to work. If I use one on its own, it works, however multiple doesn't.

My php is very basic, but if statements always get me stumped.

Here is the code

<if $fid == 19 then><a href="forms.php?id=1"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><if>

<if $fid == 20 then><a href="forms.php?id=2"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><if>

<if $fid == 22 then><a href="forms.php?id=3"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><if>

<if $fid == 23 then><a href="forms.php?id=4"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><if>

<if $fid == 28 then><a href="forms.php?id=5"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a>

<else />

<a href="newthread.php?fid={$fid}"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a>

</if>

I want it so if the fid = xx then it goes to a form. If the fid doesn't = xx it goes to the usual link.

Let me know what I need to change.

Thanks,
Cohen Smile
<if ($forum['fid'] == 15) then>
you are not closing the iF in the first set of statements, they should end with </if>
(2012-12-05, 02:59 AM)Jason L. Wrote: [ -> ]<if ($forum['fid'] == 15) then>

It works as is, but I want it to do multiple conditions. If its not 1, then it checks the other and it checks them all and if they are false, then it should go to the original at the bottom.

(2012-12-05, 03:11 AM)pavemen Wrote: [ -> ]you are not closing the iF in the first set of statements, they should end with </if>

Yeah, still doesn't do what I want it to do, because it displays two buttons and I only want 1.
(2012-12-05, 02:47 AM)cohen Wrote: [ -> ]
<if $forum['fid'] == 19 then><a href="forms.php?id=1"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><elseif $forum['fid'] == 20 then><a href="forms.php?id=2"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><elseif $forum['fid'] == 22 then><a href="forms.php?id=3"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><elseif $forum['fid'] == 23 then><a href="forms.php?id=4"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><elseif $forum['fid'] == 28 then><a href="forms.php?id=5"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><else><a href="newthread.php?fid={$fid}"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a></if>

Bit of a mess, but I've adapted the code and it should work. BTW, your <if> closing statements were incorrect, they should be </if>.
(2012-12-05, 04:09 AM)Seabody Wrote: [ -> ]
(2012-12-05, 02:47 AM)cohen Wrote: [ -> ]
<if $forum['fid'] == 19 then><a href="forms.php?id=1"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><elseif $forum['fid'] == 20 then><a href="forms.php?id=2"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><elseif $forum['fid'] == 22 then><a href="forms.php?id=3"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><elseif $forum['fid'] == 23 then><a href="forms.php?id=4"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><elseif $forum['fid'] == 28 then><a href="forms.php?id=5"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a><else><a href="newthread.php?fid={$fid}"><img src="{$theme['imglangdir']}/newthread.gif" alt="{$lang->post_thread}" title="{$lang->post_thread}" /></a></if>

Bit of a mess, but I've adapted the code and it should work. BTW, your <if> closing statements were incorrect, they should be </if>.

It works, but it needed to be $fid not $forum['fid']
Well then change $forum['fid'] to $fid. Smile
if($fid = (19)) {
//execute...
} 

else{}
That's how it works in PHP... I'm not so sure how it works in MyBB's way.
(2012-12-05, 03:31 AM)cohen Wrote: [ -> ]
(2012-12-05, 02:59 AM)Jason L. Wrote: [ -> ]<if ($forum['fid'] == 15) then>

It works as is, but I want it to do multiple conditions. If its not 1, then it checks the other and it checks them all and if they are false, then it should go to the original at the bottom.

They you want else if or a switch set up. If you understand the concept of if already the php docs will be fine for explaining those to you. A switch uses less resources if you care Wink.

For the multiple conditions for one style you would use && between the two conditions if you want both to be met for it to display that way. And || if only one of the conditions need to be met.
(2012-12-05, 04:30 AM)Seabody Wrote: [ -> ]Well then change $forum['fid'] to $fid. Smile

I did

(2012-12-05, 04:44 AM)Ben Cousins Wrote: [ -> ]
if($fid = (19)) {
//execute...
} 

else{}
That's how it works in PHP... I'm not so sure how it works in MyBB's way.

That is what I read online, but I found it didn't work. I am using what Leyton used on H4P at one point, but it was only one condition, not multiple.

(2012-12-05, 05:39 AM)Alex Smith Wrote: [ -> ]
(2012-12-05, 03:31 AM)cohen Wrote: [ -> ]
(2012-12-05, 02:59 AM)Jason L. Wrote: [ -> ]<if ($forum['fid'] == 15) then>

It works as is, but I want it to do multiple conditions. If its not 1, then it checks the other and it checks them all and if they are false, then it should go to the original at the bottom.

They you want else if or a switch set up. If you understand the concept of if already the php docs will be fine for explaining those to you. A switch uses less resources if you care Wink.

For the multiple conditions for one style you would use && between the two conditions if you want both to be met for it to display that way. And || if only one of the conditions need to be met.

Right.... I think that makes sense. Thanks Smile
Pages: 1 2