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
    Apr 2003
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    odbc_fetch_into: if no results then...

    Hi...
    I am trying to give a default value to a variable if the SQL query didn't give any results. I suspect the if-check to be wrong, but experimenting with == and === didn't give me any results...

    PHP Code:
    $db_result2 odbc_exec($db_conn$db_squery) or die (odbc_errormsg());
    $success odbc_fetch_into($db_result2$db_row2);

    if (
    $success == false) {
      
    $discipline $i 'e Discipline';
    } else {
      
    $discipline $db_row2[0];

    Thanks for reading

  • #2
    New Coder
    Join Date
    Apr 2003
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I feel stupid.. I tried everything but spellchecking the variable where I echo'ed it..

    Nevertheless, can someone explain the difference of == and === to me? I don't understand the manual...

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    == wil compiare the value.
    === will alos compaire if they are the same variabletype.

    For instance,
    0 == False can return True (--> meaning they are concidered to be equal)
    0 === False will return False (--> meaning they are NOT equal)
    Chech the manual, for strpos() to get an example of when this is important.
    It gives a fairly comprehensive illustration:
    From http://www.php.net/manual/en/function.strpos.php
    PHP Code:
    <?php
    $mystring 
    'abc';
    $findme  'a';
    $pos strpos($mystring$findme);

    // Note our use of ===.  Simply == would not work as expected
    // because the position of 'a' was the 0th (first) character.
    if ($pos === false) {
       echo 
    "The string '$findme' was not found in the string '$mystring'";
    } else {
       echo 
    "The string '$findme' was found in the string '$mystring'";
       echo 
    " and exists at position $pos";
    }
    If you woudl use a if ($pos == false), then you would get athe message that a is not found inside abc, because 0 is equal to False and to ''. But it's not identical to False.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    New Coder
    Join Date
    Apr 2003
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, this totally clears it up.. I had seen the example but didn't understand the difference from just looking at the example itself.


  •  

    Posting Permissions

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