SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    May 2003
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Choosing the right data type for a compare

    Hi,

    There is a website where members send other members an "instant" email. If they aren't logged on, they will never know, so we want to send an email notification whenever this happens.

    The MySQL db only needs 2 new columns for this to work:

    Table USERS - column "email_notification" BOOLEAN
    Table IMAIL - column "email_notification_sent" BOOLEAN

    I wanted them to be boolean, so in PHP, all I would have to do is:

    PHP Code:
    if (email_notification_sent) {
      
    //do some things

    When I went into phpmyadmin, the dropdown box didn't give me BOOLEAN, and I see from http://dev.mysql.com/doc/mysql/en/Nu..._overview.html ,

    BOOL
    BOOLEAN
    These are synonyms for TINYINT(1). The BOOLEAN synonym was added in MySQL 4.1.0. A value of zero is considered false. Non-zero values are considered true. In the future, full boolean type handling will be introduced in accordance with standard SQL.
    so, I added the columns as TINYINT(1), unsigned and nulls not allowed.

    My question is, have I selected the correct data type, to be doing this in PHP

    PHP Code:
    $query "SELECT to_ID, email_notification_sent FROM imail WHERE to_ID=$id";
    $result mysql_query($query) or die("MySQL Error. (my profil)".mysql_error());

    while (
    $row mysql_fetch_array($result))
    {
        
    $email_notification_sent $row["email_notification_sent"];
        if (
    $email_notification_sent) {
        }
        else
        {
        
    mail$to$subject$message"From: $fromname<$from>\nCc: $cc\nBcc: $bcc\n" );    
        }

    Thanks,

    Peter

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Ukraine, Khmelnitsky
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice story, correct type, IMHO.
    Sergey Bres aka tserbis, Ukraine

  3. #3
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i use char(1) for boolean type fields
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.


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
  •