can i pass data from view to controller? |
[eluser]brian88[/eluser]
Yes the userId is correct when a user comments. In my picture I posted of the dump, the commentUserId is the correct user as it differs from the postUserId(which is being used instead). Im puzzled at how to get the correct userId for comments. Here is the sql dump http://dl.dropbox.com/u/9883217/work/posts.zip and yes the post and comments is null. and im selecting everything from posts like u did and didnt change your code.
[eluser]GrahamDj28[/eluser]
That is weird. I will use your dump and get back to you in a moment.
[eluser]GrahamDj28[/eluser]
Hi, you only provided the post table. I will need the user and comments table as well.
[eluser]GrahamDj28[/eluser]
Ok, I have done some testing and here are me results. I created the user and comment tables for the testing. The columns will not match your own, but it comes down to the same thing. USER TABLE id | username | name ------------------------------------ 31 | GrahamDj | Martin Langenberg ------------------------------------ 32 | Brian88 | Brian Forum User ------------------------------------ 33 | RandomUser | Some Name Here ------------------------------------ 34 | SomeUserName | This Is His Name POSTS TABLE id | body | date | userId --------------------------------------------------- 35 | this is a post | Monday, April 30th | 31 --------------------------------------------------- 36 | yaaaa | Tuesday, May 1st | 32 COMMENT TABLE id | userId | postId | date | comment ---------------------------------------------------------------------------------------- 1 | 33 | 35 | 2012-05-02 22:46:55 | This is a response to post id 35 ---------------------------------------------------------------------------------------- 2 | 34 | 35 | 2012-05-02 22:46:55 | This is a second response to post id 35 ---------------------------------------------------------------------------------------- 3 | 33 | 36 | 2012-05-02 22:46:55 | This is a response to post id 36 THE QUERY Code: SELECT p.*, c.*, THE RESULT OF THE QUERY Link to image Before changing your code, update the query to match your table and column names and then run the query in phpmyadmin. Good luck!
[eluser]brian88[/eluser]
ahh im sorry. heres the full dump... http://dl.dropbox.com/u/9883217/blog.sql i will test your code tomorrow. thanks a ton!
[eluser]brian88[/eluser]
Thanks GrahamDj28 and gRoberts for your help. Just to sum up this long post. We had 2 ways of linking comments to posts. this was the simplest way and works fine. controller Code: // gets all posts model Code: // get all posts
[eluser]GrahamDj28[/eluser]
Hi, Glade to here it's all working now. If you use this construction, then you can change the comments query to this: Code: SELECT c.date, c.comment, As the query is now, you can select posts and their comments all at once.
[eluser]brian88[/eluser]
Im glad you posted that sql. I just ran into a problem. When posts do not have a comment yet. It just returns all null for all the table data columns. So when you create a new post, It automatically has a null comment to start with. Now it returns the whole array as null. and no more null comment. This sql fixed it. Thanks!
[eluser]GrahamDj28[/eluser]
You are welcome! Good luck with the rest! PS. If you use CI's profile you can see the number of queries being executed during a page call. |
Welcome Guest, Not a member yet? Register Sign In |