Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
php if statement
#1
Hey guys,
I am working on my plugin, and I cant figure this out:
I would like to create an if statement within an if statement, does this make sense?

I want it to look like this:
Code:
if (condition = 'condition') {
    if (2nd condition = '2 condition') {
       code to be executed
    }
}

Is this right, if so why doesn't it work for me:/ and if not, how can i do this?

Thanks
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#2
Try something like this:

$a = 1;
$b = 2;
$c = 3;

if ($a == 1) {
if ($b == 2) {
code to be executed
}
if ($c == ($a + $b)) {
code to be executed
}
}

That only works if things are true.
If something is not true and you need out put for it, then add an else clause.
IE:

if ($b == 2) {
code to be executed
} else {
code to be executed if $b != 2 // != means "does not equal"
}
Clients always want to be able to change the content of their pages, but they are unwilling to do so.

Have you ever coded in your underwear before?
Reply
#3
I changed my code, now it will only display the iPhone theme on the iPhone if the theme exists. But if it doesn't exist, it just generates a blank page...

does any one know how I could just tell it to set $TEMPLATE == (current theme)???

Thanks.
here is my current code:
Code:
// Check browser, and change theme
function sic_change_theme() {    
   global $TEMPLATE;
   $file = '../theme/iPhone/template.php';
   if (file_exists($file) !== FALSE){
     }
    else
    {
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE) {
      $TEMPLATE = 'iPhone';
        }
    }

  
    
}
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#4
Try this.

Code:
function sic_change_theme() {    
    global $TEMPLATE;
    $file = '../theme/iPhone/template.php';
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') == TRUE) {
        if (file_exists($file) {
            $TEMPLATE = 'iPhone';
        }
    }
}
Clients always want to be able to change the content of their pages, but they are unwilling to do so.

Have you ever coded in your underwear before?
Reply
#5
this causes a crash... like your missing a } or { I am looking for the error now.
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#6
with this code, it causes the whole site to crash. No pages are accessible.

I can't find any errors though..

thanks for trying to help..
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#7
The line below misses a bracket:
Code:
if (file_exists($file) {
Should be like this:
Code:
if (file_exists($file)) {
Reply
#8
I was just about to post that, but this script still doesn't work for me?

any other suggestions?
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#9
There should be a problem with the filename then.
Reply
#10
I can not find one.

I am going to attach my plugin, maybe you can look and see if you can find anything...

Thanks for your help.

######## PLEASE NOT THE FILE ATTACHED IS NOT A WORKING PLUGIN, TO GET THE WORKING PLUGIN, VISIT THE PLUGINS ######## FORUM...
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#11
First thing caught my attention is the plugin description. I'm not sure but it'd be better if you'd remove the double quotes.
Reply
#12
fixed, I did this because with just ' ' when I typed user's it ended the '.. make sense. I believe " " will work the same way though.
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#13
Wait... How is the plugin gonna decide which theme is the iPhone theme and how is it gonna load it? The plugin just changes the value of the $TEMPLATE variable to "iPhone" if the file (which has a constant theme folder name???) exists.

I think the plugin should work like this:
- Make the admin to choose the iPhone theme from a dropdown list of the themes in the plugin options page.
- Load the selected theme if the user agent is iPhone.

Otherwise, it'd just look for an "iPhone" folder in the "theme" folder.

PS: Just to be safe, let's change the plugin description line with the line below:
Code:
'This plugin automatically detects a user\'s browser and sets the theme accordingly.',    // Plugin Description
Reply
#14
I would love it to work this way, I am not good enough at PHP to write this though.

My reason for checking to see if the theme folder called iPhone exist is so if it doesn't,
it will not just display a blank page. Also, Zegnat I believe is the one who told me to change
the theme like I am wanting to all I need to do is set the $TEMPLATE to the name of the iPhone
theme if the browser is an iPhone.

If you would be willing to assist me in the code for this, I would be very willing to do this.

I think it would require the following:
Admin function with the options:
1. Enable/Disable (Using xml)
2. Select theme from list of available themes
3. Save
End user:
1. Automatically change theme to Admin selected theme
2. Enable/Disable switch (Using a cookie)

Does this all make sense?

Would you will be willing to co-develop this plugin with me?

Thanks
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#15
I'm not good at PHP either, you'd do better with someone besides me! Big Grin

Although, I don't get a blank page if the iPhone theme doesn't exist. In fact, I'm not sure but the site opens with the existing theme in any circumstances Smile).

BTW, why is there an empty array in the 7th line?
Reply
#16
I am not sure why the array was there... I took it out though.

have you tried my current release of the iPhone theme changer?

Without the if statement for file_exists($file) the theme works great, unless I rename or delete the
iPhone theme. I need it to automatically select the other theme if the iPhone theme doesn't exist.

I really wish some one would step up and co-program this plugin with me, I really think this would be
a good plugin, but I really can't do it myself.
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#17
Maybe you should set the $file variable like this:

Code:
$file = $SITEURL . '/theme/iPhone/template.php';

But of course, you'll also need to add:

Code:
global $SITEURL;
Reply
#18
nope, no good.
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#19
I edited my post and reminded that you should also add global $SITEURL;, you did that too?
Reply
#20
I added both, and it still doesn't work, I am pretty sure this is an error with the if statements.. I just can't figure out a different way to check weather the file exists.
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#21
Why don't we check just the folder? Smile

Code:
function sic_change_theme() {
    global $TEMPLATE, $SITEURL;
    $iPhoneTemplate = 'iPhone';
    $file = $SITEURL . '/theme/' . $iPhoneTemplate;
    $found = strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone');
    if (file_exists($file) && $found == true) {
        $TEMPLATE = $iPhoneTemplate;
    }
}
Reply
#22
Nope. Nothing.

I have been working on this for about 7 hours. I am getting a little annoyed.
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#23
I can't think of anything either Big Grin It's 7.20 AM here in Turkey and I'm really really tired, so I have to leave the forum for now Smile. I attached a debug version of your plugin but notice that I've made another change to the $file variable (turns out there's a constant named GSTHEMESPATH in GS core!) and as I said, I added some debug stuff (but I used echo)... Must... sleep... now... Tongue
Reply
#24
Give this a shot. I can't test as I don't have an iPhone.
This should make the $TEMPLATE var equal to "iPhone" when the user is using an iPhone.

Code:
add_hook('index-pretemplate','sic_change_theme');

function sic_change_theme() {
    global $TEMPLATE;
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') == true) {
        $TEMPLATE = 'iPhone';
    }
}

So when the below is called...
Code:
include("theme/".$TEMPLATE."/".$template_file);
It should output like this...
Code:
include("theme/iPhone/".$template_file);

Try and keep it simple. You were trying to make sure the iPhone folder exists... well, I wouldn't have this plugin if it didn't exist Wink If you want to check for that, show it off in the admin panel.
Clients always want to be able to change the content of their pages, but they are unwilling to do so.

Have you ever coded in your underwear before?
Reply
#25
This is true, some one asked for this feature so I put in a bunch of time. I currently have this plugin relleased with out checking for the iPhone folder and it works greate.

I will just add some stuff to the admin and Leave it alone.

If some one else would like to assist me in adding some options then I would be willing to work with them and seeing if we can't make this plugin better.
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply




Users browsing this thread: 1 Guest(s)