I created a node called restaurant with a cck field location. The user will be able to write about the restaurant and they have to write the location of it. I created a view that shows all location of a particular restaurant. So lets say 3 users chose to write about Olive garden. 2 wrote about the one in Los Angeles and 1 wrote about the one in New York. I expected the result to look like this:
Los Angeles
New York
but the result was this
Los Angeles
New York
Los Angeles
The view showed all the locations, even duplicate ones. Is there anyway to have views take out the duplicates. I'm thinking that I have to change the views template by using views-[field-name].tpl.php and writing a function that will show only one instance of the location. I want to know if there is a way without customizing a template or if I do have to write a separate views template.
Comments
Hi Did you tired grouping
Hi
Did you tired grouping field from where you selected style plugin. If you group by location field probably this will solve your problem.
I changed the style plugin to
I changed the style plugin to group by location, and it didn't give me the correct results. Infact, there were more duplicates. Instead of
la,nyc,la
the result was
la,la,nyc,nyc,la.
This new view showed all nodes that had these location.
My style plugin was unformatted. I was able to find out that in views-view.tpl.php that $rows shows the output of the fields. However, I am unable to figure out how views creates the $row so I can manipulate it. I tried using print_r but I'm guessing it doesn't work for this variable because it is not an array. views-view-field.tpl.php shows the output of individual fields, but I want be able to write a function there that will compare all the fields. That's how far I got trying to customize the view. is what I'm doing logical or is there another option in views that I am not seeing?
Did you figure out a solution
Did you figure out a solution to this? I'm in the same scenario.
Thanks.
I was able to figure it out,
I was able to figure it out, but the method I use was kind of complicated.
First of all, instead of cck fields I used taxonomy terms. I created separate views for the restaurant, state, and city.
First I created a restaurant node.
Then I added the taxonomy term state and city.
I copied the default glossary view and showed only the restaurant node. My page url was example.com/restaurant.
So this view will show me all of the restaurant nodes.
I changed the output of the links to this:
example.com/restaurant/[node-title] ( I will use olive garden for the title).
After this, created a taxonomy view. In the arguments, I included node title.
So base on the url, views will take in the node title to show all of the taxonomy terms for this node.
In filter, i added taxonomy vocab to show only the states. I might have used distinct to remove duplicates.
Then I changed the link output to this:
example.com/restaurant/olive-garden/[taxonomy-term]
And I just repeated the same for the other fields.
I might have forgotten some steps. What are you trying to create with views.