SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot cwebmedia's Avatar
    Join Date
    Nov 2002
    Location
    Calgary, Alberta, Canada
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If/Else Statement Problems

    I'm working on a flat-file CMS and am having troubles with simple little handler I've created.

    I've got an .info file for each page that holds some delimited variables for things like, pageName, pagePath etc. One of the variables is Auto Format which allows the admin to determine with the page content should be run through nl2br or not.

    On the admin page, I've got a handler that sorts the delimited info into some variables then displays them in an HTML form to be edited.

    My second handler is simply an if/else statement that builds a dynamic drop down depending on the Auto Format's, Yes or No setting.

    That drop down is not working. Here's the code:

    PHP Code:
    $fileName "files/info/$pageId.info";
    $filePointer fopen ($fileName"r");
    $fileContents fread ($filePointerfilesize ($fileName));

    $delimiter ",";
    $resultArray explode ($delimiter$fileContents);

    $pageName $resultArray[0];
    $pageDataFile $resultArray[1];
    $pageTitle $resultArray[2];
    $pagePath $resultArray[3];
    $autoFormat $resultArray[4];

    fclose ($filePointer); 
    Now the if/else:

    PHP Code:
    if ($autoFormat == 'Yes') { // if autoFormat is Yes, create drop down with Yes selected
        
    echo "<select name=\"select\">\n";
        echo 
    "  <option selected=\"selected\">Yes</option>\n";
        echo 
    "  <option>No</option>\n";
        echo 
    "</select>";
    } else { 
    // if autoFormat is no, create drop down with no selected
        
    echo "<select name=\"select\">\n";
        echo 
    "  <option selected=\"selected\">No</option>\n";
        echo 
    "  <option>Yes</option>\n";
        echo 
    "</select>";

    At first I had it set up that there was no delimited file but a PHP script that created an array with the needed info. That worked fine. Since I changed to the delimited file, the Auto Format dynamic drop down does not work. The rest of the variables work just fine btw. I've also taken out the above drop down code and just put in:

    PHP Code:
    echo "$autoFormat"
    To which it prints out the value no problem. I changed the == to just one = but same thing.

    What the heck am I doing here?!?!?!?

    Keep smiling ...
    It makes people wonder what you're up to ...

  2. #2
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the drop down is not working, I presume it is always defaulting to "No"?

    Try
    PHP Code:
    if (trim($autoFormat) == 'Yes') {
       
    //...

    Since you are grabbing this data from a file, you might have an unwanted new line or other foreign character present that == 'Yes' doesn't account for.

    Cheers!
    My name is Steve, and I'm a super-villian.

  3. #3
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed the == to just one = but same thing.
    = is a binary operator that sets the value on the left to the evaluation of the value on the right

    == is a binary operator that checks whether or not the value on the left is equal to the evaluation of the value on the right (ie, 'e' == 'e', '0' == 'false')

    === is a binary operater that checks whether or not the value on the left is identical to the evaluation of the value on the right (ie, 0 != false in this case)

    Just thought you should know that before you go any farther with your adventures in php
    Ryan

  4. #4
    SitePoint Zealot cwebmedia's Avatar
    Join Date
    Nov 2002
    Location
    Calgary, Alberta, Canada
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lieut_data: Once again you save the day for me!

    Gybbyl: Thanks for the heads up! That's been added to my, 'Things you have to look up and learn' list.

    Keep smiling ...
    It makes people wonder what you're up to ...

  5. #5
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No worries

    I remember having some pretty obscure bugs from things just like this
    Ryan

  6. #6
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cwebmedia
    lieut_data: Once again you save the day for me!
    It's great fun fixing people's problems (It's kinda like helping my Mom clean up the house... now, If I could just tackle my room...)
    My name is Steve, and I'm a super-villian.

  7. #7
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [off topic]
    You think helping your mom clean the house is fun? Are you crazy, or what?

    I think PHP may be getting to your brain...
    [/off topic]
    Ryan

  8. #8
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [offtopic]
    Lol -- Seeing a room turn from a frazzled array of papers and objects to an organized, structured template of beauty.... that's what I like (much like converting PERL code to PHP )

    But I can never seem to get that done with my room... nor sometimes my own code!
    [/offtopic]
    My name is Steve, and I'm a super-villian.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •