EllisLab text mark
Advanced Search
     
no_results not working in exp:query
Posted: 12 June 2012 03:13 PM   [ Ignore ]
Avatar
Joined: 2008-10-21
25 posts

Hi,

no_results is not working in exp:query for me.

My query is within switchee, so I tested it outsite, but it still didn’t work. I also tried this php method, but it didn’t work.
I tried to shorten my query and turn of php, it din’t help.

Here is my shortened code:

<ul>
 
{exp:query limit="20" sql="
 SELECT
  exp_channel_titles.title
 FROM
  exp_channel_titles
 "

  {project_list}
 {if count
==total_results}</ul>{/if}
  
  {pagination_list}

  {if no_results}
   
<p>Nothing here</p>
  
{/if}
 {
/exp:query} 

Also the closing ul always shows up. Even if there are no results.

Thanks,
Phil

 
Posted: 13 June 2012 02:10 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-18
7340 posts

Hi Philip Prinz,

Thanks for posting to the forums!

The query in your example will always return results as long as there are entries in any channel in your site.

There isn’t anything in the query that would cause it to return nothing.

Also, the limit=“20” parameter for the query module is for pagination purposes. If you need to limit the query results, you need to set the LIMIT in your statement.

Try this for your conditional:

{if {count} == {total_results}}</ul>{/if} 

Can you give me an idea of what you are trying to do? Are you sure the query module is needed?

I’ll do my best to help you to a solution.

Cheers,

 

 

 Signature 

How may I help you?

 
Posted: 14 June 2012 02:36 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-21
25 posts

OK, think shortend it too much smile
So here is my full code:

<?php 
 $member_id 
$this->EE->session->userdata['member_id'];
 
?>
 
<div id="content" class="full-width" role="main">
  <
ul class="project-list cf">
 
{exp:query limit="20" sql="
 SELECT
  exp_channel_titles.author_id,
  exp_channel_titles.entry_date,
  exp_channel_titles.title,
  exp_channel_titles.status,
  exp_channel_data.entry_id,
  exp_members.member_id,
  exp_members.username,
  exp_members.screen_name
 FROM
  exp_channel_titles
  LEFT JOIN exp_channel_data ON exp_channel_titles.entry_id = exp_channel_data.entry_id 
  LEFT JOIN exp_members ON exp_channel_titles.author_id = exp_members.member_id
 WHERE
  exp_channel_data.channel_id = '2' AND exp_channel_titles.status >= 'open' AND NOT exp_channel_titles.author_id = '<?php echo 
$member_id; ?>' AND exp_channel_titles.entry_id NOT IN (SELECT entry_id FROM exp_vz_average WHERE user_id = '<?php echo $member_id; ?>')
 ORDER BY exp_channel_titles.entry_date DESC
 "

  {project_list}
  {if count
==total_results}</ul>{/if}
  
  {pagination_list}

  {if no_results}
   
<p>Congratulationsyou have voted for all projects!</p>
  
{/if}
 {
/exp:query}
 
</div><!-- Content End --> 

In other words I want to show entries where the current member has not yet voted for.

The </ul> will show with {}, too. In all my other cases it works without brackets. Maybe it’s the same issue the no_results does not work.

 

 
Posted: 15 June 2012 03:58 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-18
7340 posts

Hi Philip,

I really want to help, but SQL is outside the scope of support. I’ll move this into Development and Programming for input from the talented Community.

Cheers,

 Signature 

How may I help you?

 
Posted: 16 June 2012 02:21 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-21
25 posts

But exp:query is a standard tag … well, ok.
Have you already moved it? I cannot find my question in Development and Programming.

 
Posted: 18 June 2012 05:07 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-18
7340 posts

Hi Philip,

Indeed, Query is standard, but the SQL itself is where we aren’t able to help.

That’s why it comes more in line with Dev and Prog.

Cheers,

 Signature 

How may I help you?

 
Posted: 19 June 2012 08:20 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-15
426 posts

Is this inside of a {exp:channel:entries} loop?

 Signature 

ExpressionEngine Development | 21purple Web Studios, LLC or on Twitter @th3mus1cman