I know that UNION is not supported. But is there ANY alternative methods for creating something like the attachment illustrates? Thank you and thank you!

CommentFileSizeAuthor
recordset-mockup-001.png52.67 KBsorensong

Comments

merlinofchaos’s picture

Status: Active » Fixed

You could use hook_views_pre_render(), run execute an alternative display (recommend an attachment that is not actually attached to anything), then merge (and sort!) the $view->result setup. They would have to have exactly the same fields.

You could probably also do something really whacky by creating a view style, as well, that could run an attachment and attempt to sort in the rows. Doing it that way would probably not require anything about the two views being the same, so long as they're using row plugins, but you'll still have to somehow sort the result rows.

merlinofchaos’s picture

A third alternative might be to run two views that just returns node IDs, then set all those node IDs as an argument to a 3rd display.

sorensong’s picture

Thanks a bunch for your continued effort in this unexpected dilemma. I'm not sure what the forum guidelines are, but would it be possible to email you? I have a proposal.

nevets’s picture

What is different about the queries, I can imagine ways to do that with one query but it depends on how the queries are different.

sorensong’s picture

So basically, what I'm trying to do is

-Display all 'content type A'
-If user of node is 'regular' then show basic basic fields (name, phone number).
-If user of node is 'pro' then show phone number plus extra fields (picture, description, extra links, etc...)

If this thing would be too involved to accomplish using backend techniques, I've flirted with the idea of some sort of a js/css hack using display:none. Unfortunately I'm not well versed in js. :/

sorensong’s picture

ACTUALLY... if there was a module that simply turned 'Hide if empty' in to 'Hide if', that'd work perfectly! Could simply insert some SQL conditions. Might work, no?

sorensong’s picture

Any ideas, anyone?

merlinofchaos’s picture

You could do some preprocessing on the rows to check the data on the user and, if it isn't a pro, set all the other fields to NULL. You'd do that hook_views_pre_view() and you'd have to be careful about 'group multiple' things. You'd need to unset data on the handler for that.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mstrelan’s picture

hook_views_pre_render() as mentioned in #1 worked great for me, but be warned that it may have issues with pagers.

My code below for reference if anyone wants it.

<?php
/**
 * Implements hook_views_pre_render().
 */
function MYMODULE_views_pre_render(&$view) {
  if ($view->name == 'MYVIEWNAME' && $view->current_display == 'MYDISPLAYNAME') {
    $other_view = views_get_view('MYVIEWNAME', TRUE); // <--- not sure if TRUE (reset) is required
    $other_view->set_display('MYOTHERDISPLAYNAME'); // <--- important
    $other_view->execute();
    $view->result = array_merge($view->result, $other_view->result);
  }
}
?>
skrtvm’s picture

Issue summary: View changes

why cant you go for Views Merged Rows - D7?

https://www.drupal.org/project/views_merge_rows