0

I want to store data of news Feed . News feed contains image , video , audio , text . How to store all these together in database ?
I have table

post(postid , userid , post_content , post_time);

For Video ,audio and image we are using directory For every user. So when ever they will upload video , audio , image then this will be stored in their directory . But how to put all these together in database . So that we can apply classes to style image , text e.t.c , I am unable to combine all these and put together so that this it can be stored in Database as content.

I have idea like this

post(postid , userid , text_content , post_type , post_time);

post_image(id , postid , path);

post_video(id , postid , path );

post_audio(id, postid , path );

post_type is used for image = 0 , video = 1 and audio =2 assuming user can post only one of them either image or video or audio .

Is this a good idea to store News Feed in database . Any help will be appreciable .

I am using PHP , MYSQL , Apache .

user3610792
  • 61
  • 4
  • 14
  • Just store the location for each of the user's data in a table and get it from the database when you need it :/. make sure you escape the string with mysqli_real_escape_string(); – ksealey May 13 '14 at 08:35
  • Why people down vote , it's not a good question ? or it's not a question for Programmer ? What are the reasons to down vote ? – user3610792 May 13 '14 at 09:18
  • People are downvoting your Question because you don't show any code from yourself, it's a little bit like a "do my homework" question. You need to show off what you've tried, what you want to achieve and the point where you are struck. I can see that you are thinking about that yourself, so i'm helping you, but to increase the quality of your question you could and should add your code :) – KhorneHoly May 13 '14 at 09:24
  • And btw: Welcome to Stackoverflow :) Here is a [link](http://stackoverflow.com/help/how-to-ask) with great information about how to ask good Questions on SO, so you will not be downvoted in the future and you questions will get more attention :) – KhorneHoly May 13 '14 at 09:31
  • Every question doesn't require Code to show what you have done and what you want ? I need just suggestion and Idea , don't require any code to do and also it's not my HOMEWORK . – user3610792 May 13 '14 at 09:43

1 Answers1

0

Here is an similar question here on SO with further information and references how you could save images and audio in MySQL.

BUT IT'S NOT RECOMMENDED

Each file will have a few MB, so your MySQL Database will grow pretty big.

As @ksealey mentioned in the comments you need to store the path to the saved file in the database, this is best practice for MySQL Databases and the common way to do it.

Instead of hardcode the path to the file you just refer to the database entry for the images and audios.

Community
  • 1
  • 1
KhorneHoly
  • 4,666
  • 6
  • 43
  • 75
  • It's fine that i should store path only but how to find inside text that text contains image or video or audio .. – user3610792 May 13 '14 at 09:15
  • You could use an `switch case` or `ìf else` block to check the strings with [strpos()](http://www.php.net/manual/en/function.strpos.php). Just something like `if (strpos($path, '.jpg')){ // it's an .jpg image }` and so on – KhorneHoly May 13 '14 at 09:20
  • What about storing data individual , as i explained in question(updated) . – user3610792 May 13 '14 at 09:21
  • That's an idea, but you only could save either one of the 3 kinds, but you surely want to have newsfeeds with video and images or something like this. What you could do is to add a field in your post table, like `post_attachment_id` and then create a new table `post_attachment` where you save the `path` and `post_id`. This referes to the post with an One (post) to many (post_attachment) relationship – KhorneHoly May 13 '14 at 09:29
  • That's good , I can one more field to post_attachment as post_type which refers to type of attachment so that i can easily add CSS and JS and define table post as post(postid , userid , text_content , attachment, post_time); i have used attachment to identify that attachment is there or not so we can save time for join . – user3610792 May 13 '14 at 09:32
  • Just one more thing: To help stackoverflow to keep its Question/Answered Question Ratio high you should accept my answer if it solved your problem, which always grants you and me reputation, which is also usefull :) You find the button for it under the arrows to rate my Answer, i would appreciate it! :) – KhorneHoly May 13 '14 at 10:53