SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: SET in MySQL?

  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    SET in MySQL?

    I have chosen a thing called set in MySQL. I thought it was supposed to be used when you have like a couple of alternatives to chose between. So I did put some of them in my database and then using Dreamweaver to code the stuff in php.
    I have a dropdown menu to show the alternatives, but it doesn't work at all. Nothing is shown in the menu at all.
    So, I made one link to another table to pick like usernames from the other table and that one works.
    Isn't SET the thing I would use to list like 3 alternatives in a form?

    This is the code that doesn't work.

    HTML Code:
    <option value="<?php echo $row_Recordset1['places']?>" <?php if (!(strcmp($row_Recordset1['places'], $row_Recordset1['places']))) {echo "SELECTED";} ?>><?php echo $row_Recordset1['places']?></option>
    Oh sorry... got to tell you that I'm a newbie.

    ;-)

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi brad,
    Basically SET is used when updating a database record eg
    UPDATE mytable SET id='$id' etc.....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by spikeZ
    Hi brad,
    Basically SET is used when updating a database record eg
    UPDATE mytable SET id='$id' etc.....
    I think he's using the Set datatype in mysql, not the SET keyword for SQL statements.

    I would recommend that you not use it. It's a cheap shortcut way of skirting referential integrity.Create another table with your options and pull them by querying that table.

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yeah, you're right. I'm using SET in MySQL.
    But I have several things like that in my form. Then I need a lot of tables.
    Thought this was an option when you don't want a lot of tables and save some time.

    So, I will have to start makin tables now.

    :-(

    Thanx anyway.

    Brad

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i would use a few more -- and stronger -- adjectives besides "cheap"

    stay away from SET and ENUM types
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by brad62
    Yeah, you're right. I'm using SET in MySQL.
    But I have several things like that in my form. Then I need a lot of tables.
    Thought this was an option when you don't want a lot of tables and save some time.
    You'll save time now but you'll pay for it later when you want to make a change.

  7. #7
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    The only time I use SET is when I need to store simple values that I know are the only things the column can have. Such as 'Y','N'. But, I never use SET in a foreign key because like Vinnie said, referential integrity goes straight out the window.

  8. #8
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Hartmann
    The only time I use SET is when I need to store simple values that I know are the only things the column can have. Such as 'Y','N'. But, I never use SET in a foreign key because like Vinnie said, referential integrity goes straight out the window.
    In that case I'd just use a char(1) with 'y' and 'n', or a 0/1 int(). Easier to port to different databases later if that's an issue.

  9. #9
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    In that case I'd just use a char(1) with 'y' and 'n', or a 0/1 int(). Easier to port to different databases later if that's an issue.
    Yeah, we aren't really thinking about portability but you have a good point.

    I was taught not to use 0/1 because they are considered abstract and shouldn't be used as bools (but I still do it ).

  10. #10
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Future use

    Seems like people talk about future uses here to make things simple.
    When using a Y or N. I should use VARCHAR(1).
    But what makes that easier for future use? I didn't get that part.

  11. #11
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    if you are using Y and N, use CHAR(1)

    the "future use" aspect is that if you have to move your application to some other database, they all support CHAR

    but only mysql supports SET and ENUM
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •