Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with IF STATEMENT

    I am trying to access a database table field called "Category" from a database named 1.

    The output of everything else works great, however, I am trying to get an if statement working on the data that is output.

    Category has a numeric value of 1-3.

    PHP Code:
                 if ($row->Category == '1')
                    {
                        echo (
    "Products");
                    }
                else if (
    $row->Catgeory == '2')
                    {
                    echo (
    "World");
                    }
                else if (
    $row->Catgeory == '3')
                {
                    echo (
    "lol");
                } 
    Can someone tell me what I am doing wrong?
    If Category field value = 1, then output Products, if the category field in the database has a value of 2, then output world, etc etc.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    There is nothing wrong in if-else statement.
    Are you sure about the value of $row->Catgeory.
    Try to echo its value before this block and check if it's correctly assigned through your query.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The Category statement is working fine.
    If Category contains a numberic value of 3, and I type:
    Code:
    echo (".$row->Category.");
    Then 3 will be output.
    Can you revise the IF statement and make sure it will work with database query calls such as the $row->Category.

    I tried different syntax and possibilities. Sometimes, I get text output of the words, but its not the correct listing.

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was able to solve it. Much Thnaks!


  •  

    Posting Permissions

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