Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/64561-simple-author-of-news-problem/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.