By steveadamo on
I've been Googling my fingers to the bone, and trying all variations of:
$view1 = views_get_view('activity_center_events_page');
$view1->get_total_rows = true;
$view1->execute();
$viewrows = $view1->get_total_rows;
if ($viewrows > 0) {
echo 'rows...';
}
Unfortunately, all for not... can someone enlighten me on simply how to determine if a view has no results? I am trying to manually embed two views, and depending on if the first has any results, I'll display the second.
Oh, and I've tried setting the empty string in the view to text as well as deleting the contents.
Comments
just for grins, i've also
just for grins, i've also tried checking for a result from
this failed as well, and i think ive fallen into desperation coding, as i know im being horribly innefficient now...
hmm... looking into this
hmm... looking into this thread now...
http://drupal.org/node/446798
Here is one approach, make a
Here is one approach, make a view that represents block 1, add an attachment that represents block 2.
Now make a modified copy of the theme file for "Display output". I would pick one of the names specific to the view. The default theme file has a part like
Change to
to have the attachment only show when the block view is empty. You can also do the same for $attachment_before.
interesting approach... im
interesting approach... im not entirely sure how to create an attachment, but ill look into it...
out of curiosity, why is this code snippet not returning the expected results?
i dont think this approach
i dont think this approach will work in my case, as the views take different arguments (and display fairly different sets of data), and it seems as though the nature of an attachment is to inherit from its parent...
im just baffled as to why the code snippet i posted above is not working in my case...
Awesome! This is such a great
Awesome! This is such a great trick and helped me out immensely! Thanks for posting it... :)
If you have, for example, nid
If you have, for example, nid as one of your fields, you could check if a nid was returned:
Check out this thread and see
Check out this thread and see if what I posted works for you as well. It seems to work for me so far.
When using views_embed_view this is what i did
for a view that creates a table i just did a pregmatch to see if there is a "table" tag. Then i know its not empty.
Thank You!! I've been trying
Thank You!! I've been trying to use views_embed_view in a Tab to display videos. But I didn't want to see the Tab if the view was empty! The preg_match technique did the trick. (Although I wonder if there is a more elegant solution?)
thanks
this worked for me too.
Empty or Not Using Arguments AND Displays
This is the approach I use when i need to determine if a view is empty or not, this code allows for arguments and different displays. If no arguments then just omit the set_arguments line.
If you want to get the output of the view inside the if statement, you can just add this line, since the display and arguments are already set. Rather than using views_embed_view().
Don't know why...
... but here it only works if i have advanced content profile kit active..
Either the displayed above as well as the $view->preview() thing.
Strange uh.
in the event this helps
in the event this helps anyone, i just used,
Hope this helps!
pete
Toronto Website Developer