Re: Struggling with creating a function and search an array then outputting data based upon results...
Hey mate! Thanks for your help but I solved the problem a couple of hours ago. What I did was first get the items, then I simply extracted the data, in this case the votes, from those items, then after that I set a variable to the funciton in_array. Then depending on the outcome of that the css file is set. Thanks for your help though ! On Jul 8, 5:21 pm, wralph <[EMAIL PROTECTED]> wrote: > You could write a component for checking if the user_id is contained > in the data array. So something like: > > class VoteInfoComponent extends Object > { >function userVoted($data, $userid) >{ > if (is_array($data) ) > { > foreach($data as $story) > { > foreach($story as $votes) > { >if ($votes['user_id'] == $userid) return 1; > } > } > } > return 0; >}} > > ?> > > I haven't tested the above! Include this in your controller and then > call as > > $this->voteinfo->userVoted($data, 74); > > It would be easy to extend this to check if a user responsed to a > particular story. > Also you have an error in the following: > > > > should be > > > > Winston --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Struggling with creating a function and search an array then outputting data based upon results...
You could write a component for checking if the user_id is contained in the data array. So something like: I haven't tested the above! Include this in your controller and then call as $this->voteinfo->userVoted($data, 74); It would be easy to extend this to check if a user responsed to a particular story. Also you have an error in the following: should be Winston --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Struggling with creating a function and search an array then outputting data based upon results...
I have been trying to figure this out for the past 2 hours and to no avail. :/ So any advice is GREATLY appreciated. Ok, I have an array that returns data like this (see array below) The array[0] contains all the votes for one story as well as information that pertains to that vote, and the array[1] contains vote information for another story. What I need to do is check is a user_id stored in a session, is in the array, and then create a boolean array from that. For example, here I want to check if the user_id is featured in the first set of data, let's say my user_id is 74. Ok, so it is in the first set of data, so we set the boolean variable to true. Next I need to search the second data field for my user_id, 73. It is not featured here so the value in my array is set to 0. I need an array that returns values either 1, for true, your user_id was found in the table, or false, for your user_id was not featured in the table. They need to be in order of the story too. I'm having trouble one comparing the two variables against eachother, since the array is very deep, and two, creating the array on the fly. Any suggestions are recieved with open arms! Thanks for looking ! Array ( [0] => Array ( [0] => Array ( [id] => 5 [story_id] => 122 [user_id] => 74 ) [1] => Array ( [id] => 6 [story_id] => 122 [user_id] => 74 ) ) [1] => Array ( [0] => Array ( [id] => 7 [story_id] => 123 [user_id] => 74 ) [1] => Array ( [id] => 8 [story_id] => 123 [user_id] => 74 ) [2] => Array ( [id] => 9 [story_id] => 123 [user_id] => 74 ) ) ) [1] => Array ( * => Array ( [id] => 7 [story_id] => 123 [user_id] => 45 [Story] => storythree ) ) ) P.S. The reason I am trying to return a boolean array is because they will set a value in the view in a div tag for the class, like so --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---