Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Adding A Boolean To My Column Type

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Adding A Boolean To My Column Type

    I need to add a column in my database, which will be called 'MemberPackSent' basically I want to send out a pack to members, just wondering would I make this a Boolean? Do I need to specify the 'Length' or is a Boolean simply always 1 or 0?

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Boolean can be 1 or 0, but you can make it "true" or "false" as well. I know in PHP true and false boolean tags are read as 1 and 0 anyways, if you try to echo them.
    As long as you don't get too confused, 1 and 0 are fine.
    - Mike

  3. #3
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ahhhhh ok is there a way in php that if it was a '1' value I could convert it to 'Yes'?

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    if ($value == 1) {
      $value = "Yes";
      } else {
      $value = "No";
      }
    - Mike

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    $value = $value ? "Yes" : "No";
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Huh?
    Shouldn't:
    Code:
    $value = $value ? : "Yes" : "No";
    Be
    Code:
    $value = $value ? "Yes" : "No";
    - Mike

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes, sorry, typo. Corrected.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Apr 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi tomy,

    Yes, sure you can assign the value using simple “if” condition before updating database.

    Here is the basic code to do this..

    Code:
    <?php
    $con = @mysql_connect(“Ip Address”, “username”, “password”) or die(mysql_error());
    
    $db = @mysql_select_db(“emp”, $con) or die(mysql_error());
    
    $packets = true;
    If ($packets = true)
    {
    $Val = 1;
    }
    Else
    {
    $val = 0;
    }
    
    ?>
    After converting the value you can simply insert it into the database using SQL statements.
    Last edited by tech_support; 04-16-2007 at 09:12 AM. Reason: Please wait until you have 5 posts before inserting a signature.

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Some versions of MySQL will accept "true" and "false" as keywords and convert them automatically.
    Code:
    $con = @mysql_connect(“Ip Address”, “username”, “password”) or die(mysql_error());
    Watch the "smart quotes" -- that won't even parse as PHP.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Off the topic of connecting, but mysql_query allows it:
    Code:
    SELECT * FROM blah WHERE test=“foo”
    so in PHP, you could do
    Code:
    mysql_query('SELECT * FROM blah WHERE test=“foo”');
    - Mike

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
  •