0

What is the max length of an PHP array .. My requirement is

There are about 4000 movies in my database and there are so many users , now 1500 ( increasing) . Each member can rate the movie only once.

So I made a row in my user table that will store in which movies user rated. I m saving that in the following format

user_id   |  rated_films
-----------------------------------------
12        |  1111,1025,3541,2354,1584,3691,2451

Each time when an user hit of rating button I will check with this column ..

Is it the correct way. And I am wondering if I made a separate table for this rating like

user_id  |  Film_id
---------------------
12       |  10245
12       |  20145

Is thhis will hang the process of the application ? Suppose if all users will rate all the movies

Please help me with the correct code

Thanks

6
  • you are only limited with memory_limit. so i'd prefer second approach since it's much better for joining tables and putting some logic into sql Commented Jan 25, 2012 at 7:56
  • 1
    Either way, you will want to normalize your table and go with the second option. Anything else will become a mess and paint you into a corner sooner or later. Commented Jan 25, 2012 at 7:58
  • 1
    I dont understand, what your question has to do with PHP arrays. Regarding your database layout: the 2nd way is the standard normalized way, to store this kind of information. And it will be the better way in nearly every scenario. Commented Jan 25, 2012 at 7:59
  • If you go with the first option, you will never know how many and which users have rated which film. Say you open a page with film X and want to list all users that have rated... you just can't construct a query that will return that info. (Well, you could get this info, but in a resource intensive/expensive way). So as others said - second way. Commented Jan 25, 2012 at 8:06
  • If you're using really big arrays, can I recommend looking at Judy Arrays Commented Jan 25, 2012 at 8:07

2 Answers 2

1

Your second solution is the way to go with a many-to-many relation table. The first solution is far to kludgey. It seems unlikely every user will rate every movie and your queries will probably be more contained anyway so it should be easy for mysql to handle this.

Sign up to request clarification or add additional context in comments.

Comments

1

I think there is no limit. The problem is the memory. you can edit the memory php is allowed to user in the php.ini. In my opionion you should not use an array for this task. It is a database task. If you need something in array you should use a limit.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.