jxrd Posted June 14, 2009 Author Share Posted June 14, 2009 Well, a logical way would be to prevent it from being that value in the first place imo. It just doesn't seem "neat" to me to make sure my code doesn't accept random values... Just me though Quote Link to comment https://forums.phpfreaks.com/topic/161802-have-second-field-contain-the-id/page/2/#findComment-855593 Share on other sites More sharing options...
haku Posted June 15, 2009 Share Posted June 15, 2009 So make it NULL instead. edit: one thing you may not realize is that FALSE is also equal to zero, so if you are testing for the parent item, any number greater than zero is TRUE. So you can do a query for the parent item, then use a test like: if($parent_item) { // do some stuff } And since only items greater than zero - i.e. having a parent - will be TRUE, this will work well for you. In this manner, having a zero in the table is a good thing. Quote Link to comment https://forums.phpfreaks.com/topic/161802-have-second-field-contain-the-id/page/2/#findComment-856190 Share on other sites More sharing options...
jxrd Posted June 15, 2009 Author Share Posted June 15, 2009 Yeah...I guess I could. It just doesn't seem neat to me I appreciate that it's probably a better option...but I think I'll leave it as is for the moment. I'm a bit OCD about the neatness of my db/code. I think it makes sense to have the two fields the same. For example, the interface for editing post permissions and thread permissions is one in the same. In order to get the ID of the parent thread (to check current user is allowed to edit permission etc) all I have to do is $id = $fetch['Thread'] and I have the id of the thread, or post (no matter which type it is). Whereas, if `Thread` was 0 if it was actually a thread, I would have to do something like $id = ($fetch['Type'] == 'post') ? $fetch['Thread'] : $fetch['ID']; Which is...not as neat Quote Link to comment https://forums.phpfreaks.com/topic/161802-have-second-field-contain-the-id/page/2/#findComment-856216 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.