olilish Posted February 21, 2010 Share Posted February 21, 2010 Hello, I have a simple contact form that adds an entry to my mysql database.I would like my website to only display 'approved' entrys. I need my client to access all entrys in the database and then choose to approve, edit or delete them.I have figured out the editing and deletion part. So, my question what is the best way to have an entry approved?My initial thought is that I could have a field in my table that is simply 'true' or 'false'? - and therefore my website could display only 'true' records in my table.If this is correct, it would be great if someone could give me a place to start!Thanks! Link to comment Share on other sites More sharing options...
astralaaron Posted February 22, 2010 Share Posted February 22, 2010 either that or maybe a temporary table for un-approved. Link to comment Share on other sites More sharing options...
Synook Posted February 22, 2010 Share Posted February 22, 2010 The best way is just an additional field. Link to comment Share on other sites More sharing options...
olilish Posted February 25, 2010 Author Share Posted February 25, 2010 Any ideas on what type of field to use? - is there a simple on/off field? Link to comment Share on other sites More sharing options...
ShadowMage Posted February 25, 2010 Share Posted February 25, 2010 I'm not really sure if MySQL has a boolean type, but what I do is use an integer value. 0 equals false and 1 equals true. Then its as simple as: if ($test !=0 ) { //true //...do something} else { //false //...do something else} Link to comment Share on other sites More sharing options...
justsomeguy Posted February 25, 2010 Share Posted February 25, 2010 I typically use an unsigned tinyint with a size of 1. Link to comment Share on other sites More sharing options...
jeffman Posted February 25, 2010 Share Posted February 25, 2010 Don't sweat the type. I can only guess what goes on internally, but almost no one messes with individual bits anymore. It's only efficient if you're using enough bit flags to fill a whole byte. If MySql does have a Boolean type, it's probably just for convenience. Most systems these days use a whole byte or even a whole native word (up to 64 bits) to store a Boolean. The data pointer alone is going to use up 64 bits just to store the address of the value. So what's the virtue in saving 7 bits or 63 bits in the place the pointer points to? And what would you do with the other 7 or 63 bits?Maybe the chip in your HVAC thermostat conserves memory like that, but it seems pretty old fashioned for a big old server. Link to comment Share on other sites More sharing options...
ShadowMage Posted February 25, 2010 Share Posted February 25, 2010 I typically use an unsigned tinyint with a size of 1.Same here it was just easier to type 'integer' Link to comment Share on other sites More sharing options...
olilish Posted February 25, 2010 Author Share Posted February 25, 2010 Ok, so would I need to have every entry submitted include an integer of 0 and have my clients admin show records WHERE "approved" = 0.I would then need to have my client 'approve' an entry by editing my "approved" field to 1.Then in the main webstie I would only display entries WHERE "approved" = 1.Does that sound correct? Link to comment Share on other sites More sharing options...
ShadowMage Posted February 25, 2010 Share Posted February 25, 2010 Sounds about right. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 25, 2010 Share Posted February 25, 2010 For other similar situations where you have a limited number of possible values, an enum field comes in pretty handy. If you have a field that could have one of, for example, four values (like User, Guest, Moderator, Admin), you could use an enum field and list those four values as choices. An enum would be more efficient than a varchar field because instead of storing one or more bytes per character it would only store an integer that would point internally to the value you picked, sort of like an array of values where you store the array index instead of the actual value. So you could also use an enum field to store true/false, and it would basically work the same as an int field internally. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.