Kemik Posted August 12, 2007 Share Posted August 12, 2007 Hello, I'm making an addnews.php file. I have a form with Date, Title, Content and Author fields. How would be best to store the author, by their user_id or username? Storing by username would make my life much easier and username's cannot be changed unless edited via the database. Linking by user_id does have it's benefits but when I go to edit the article I won't have a clue who user 37 is unless I pull the user_id, query the database and put the username in the field. Then when updating the field query the database for the user_id of username. Do you think I should go with username over user_id? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/64561-simple-author-of-news-problem/ Share on other sites More sharing options...
Orio Posted August 12, 2007 Share Posted August 12, 2007 If you have to choose one of them, I'd choose the id. It just offers much more than the username, and it's not a big deal to run another query to fetch the username by the id. But if you feel a bit lazy right now, how about them both? Then you can have the flexibility the id offers and the simplicity of the username This way in the future you will able to upgrade your scripts much more easily. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/64561-simple-author-of-news-problem/#findComment-321822 Share on other sites More sharing options...
Fadion Posted August 13, 2007 Share Posted August 13, 2007 Ids are stored as primary keys so your queries would be a bit faster. Also the main advantage of selecting ids is that ure sure that record will be unique. I'd suggest going for the ids and when u edit an article, another query wont do nothing, espacially if it will be for the back end system which wont have so much traffic as the front ent. Quote Link to comment https://forums.phpfreaks.com/topic/64561-simple-author-of-news-problem/#findComment-321966 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.