ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

{exp:query} and {if no_results}

December 31, 2008 5:58pm

Subscribe [4]
  • #1 / Dec 31, 2008 5:58pm

    cshort

    59 posts

    Has anyone had problems with the no_results variable in the following way?

    When it’s in an {exp:query} tag, it adds the HTML that’s contained within the {if no_results} conditional after every row displayed from the query even though there are results.  The query tag is also using the built-in pagination, but it doesn’t affect the result if I remove it.

    I have this called from an embedded template, and it’s contained within anything but some conditional statements in the primary template. 

    The other developer on this project says that the no_results conditional hasn’t worked for sometime on the entire install (two sites within MSM,) but hasn’t had time to find a solution.  How long it’s been since it was working he doesn’t remember.

    Thoughts, suggestions?  I’ve gone back through the forum on entries related to this to as far back as 2005. Most of the problems concern nesting issues which don’t apply here.

    Expression Engine
    Version: 1.6.6
    Build #: 20081114

    MSM
    Version: 1.1
    Build #: 20081024

  • #2 / Dec 31, 2008 6:13pm

    Lisa Wess

    20502 posts

    Cam you post the code that you’re using please, cshort? And surrounding code.

  • #3 / Dec 31, 2008 6:28pm

    cshort

    59 posts

    This is the embedded template account_list

    <table class="tablesorter" border="0" cellpadding="0" cellspacing="0"> 
            <thead> 
            <tr> 
                <th>Account Name</th>
                <th>Account Number</th>
                <th>Account Key</th>
                <th>TSM</th>            
            </tr> 
            </thead> 
    
            <tbody>
    
        {exp:query limit="25" sql="SELECT acc_name, acc_num, keycode, screen_name FROM tsm_keys, exp_members WHERE tsm_keys.user_id = exp_members.member_id ORDER BY acc_name"}
    
            <tr> 
                <td>{acc_name}</td>
                <td>{acc_num}</td>
                <td>{keycode}</td>
                <td>{screen_name}</td>            
            </tr> 
    
    {!-- IF NO RESULTS RENDER THIS ROW --}
    {if no_results}
            <tr>
                <td colspan="5">{no_results}</td>
            </tr>
            </tbody>
        </table>
    {/if}
    
        {paginate}
            </tbody>
        </table>
        <div id="paginate">
            
            <div id="pg_num">
             {current_page} of {total_pages}
            </div><!--/pg_num-->
            
            <div id="next_prev">
            {if previous_page}
            <a href="http://{auto_path}">Previous</a>
            {/if}
    
            {if next_page}
            <a href="http://{auto_path}">Next</a>
            {/if}
            <div class="clear"></div>
            </div><!--/next_prev-->
        <div class="clear"></div>    
        </div><!--/paginate-->
        {/paginate}
        {/exp:query}

    The template that holds it is

    {html_open}
    
    <title>Retail Accounts</title>
    
    {html_css}    
    {html_js}    
    {html_head_close}
    {embed="contest/html_body" body_id="{if segment_3 == ""}{segment_2}{if:elseif segment_3 != ""}{segment_3}{/if}"}
    {html_wrapper_open}
    {embed="contest/html_masthead"}
    
    
    {!----------------------------
        LIST ALL RETAIL ACCOUNTS
    -----------------------------}
    {if segment_3 == ""}
        
        {html_container_open}
        {embed="contest/account_list_all"}
        {html_container_close}
    
    {!-- additional conditionals here --}
    
    {/if}
        
    {embed="contest/.html_footer"}
    {html_wrapper_close}
    {html_body_close}

    This issue isn’t limited to just this particular setup but appears to be happening site-wide.

  • #4 / Dec 31, 2008 7:20pm

    Derek Jones

    7561 posts

    Try this on a brand new, empty template, please, cshort:

    {exp:query sql="SELECT * FROM exp_sites"}
    {site_id}
    
    {if no_results}
      <hr >This shouldn't be here!
    {/if}
    {/exp:query}

    And then see if the behavior is identical.  If possible, post a link to this reduction template.

  • #5 / Dec 31, 2008 8:01pm

    cshort

    59 posts

    This is the html that the page returns:

    2
    
    
      <hr >This shouldn't be here!
    
    
    2
    
    
      <hr >This shouldn't be here!
  • #6 / Dec 31, 2008 8:09pm

    Derek Jones

    7561 posts

    Interesting, that’s two things wrong: it should not be returning two results for the same row, and of course, the no_results portion should not be displayed.  Has there been any direct database manipulation on this site, or a move to a different server / host?  And are there any extensions or hacks in place?

  • #7 / Dec 31, 2008 8:43pm

    cshort

    59 posts

    There has been no direct manipulation to EE core tables.  I’m also not aware of any moves or hacks.  I maybe corrected on this though.

    We have a handful of modules installed, in particular the user module.  There are 11 plugins and around the same number of extensions. One extension is a custom one written by me which deals with user registration and the user module, the rest were downloaded through this site to my knowledge.

  • #8 / Dec 31, 2008 8:45pm

    Stephen Slater

    366 posts

    Hi Derek,  I’m in on this project as well…  This site runs on the MSM and it’s relatively new.  It’s never been moved around to different server/host.  No database manipulation and no hacks.  We are using quite a bit of extensions including one(auto-title) that I managed to put together myself from these forums.  Here is a list:

    - ext.autotitle.php
    - ext.cloner.php
    - ext.edit_tab_ajax.php
    - ext.filter_by_author.php
    - ext.fresh_variables.php
    - ext.keycheck.php
    - ext.mh_file_ext.php
    - ext.lg_mf_customiser.php
    - ext.publishimprove.php
    - ext.saef_redirect.php
    - ext.simplify_edit_table.php
    - ext.user_ext.php
    - ext.weegee.php

  • #9 / Jan 01, 2009 12:25am

    Derek Jones

    7561 posts

    Just in case one of these extensions is doing something funky, disable them all safely by clicking the big green “Disable Extensions” button in the extension manager, which just flips a switch and won’t lose your individual extension settings.  Then access that template again and see if the results are the same.  If they are, then run that same query in the SQL Manager, and if need be, phpMyAdmin or an external database tool.  If none of that points at a likely culprit, then we’ll start looking at the environment, as that’s quite, well, wonky.

  • #10 / Jan 02, 2009 10:39am

    cshort

    59 posts

    After disabling extensions and running that template again I get the following:

    2
    
    
    
    2
    


    Now, if I run the query in the SQL Manager Query Form, it gives back both of the sites installed correctly, not two instances of the site that the template is hosted on.

  • #11 / Jan 02, 2009 11:37am

    cshort

    59 posts

    Derek,

    After going through each extension, uninstalling, testing and reinstalling extensions, there turned out to be a variable conflict due to Fresh Variables.

    That takes care of issue #1, the return of site ID #2 only remains.  Any suggestions on this one?

  • #12 / Jan 02, 2009 12:25pm

    Derek Jones

    7561 posts

    Ah, there was a Fresh Variable named “no_results” I gather?

    The goof on the second one, yeah, that’s me, forgetting a particular variable’s parse order :😊:  try this:

    {exp:query sql="SELECT site_id AS queried_site_id FROM exp_sites"}
    {queried_site_id}
    
    {/exp:query}
  • #13 / Jan 02, 2009 12:42pm

    cshort

    59 posts

    Yep, you gather correctly… 😊

    That query worked, so looks like we’re good.  Thanks for the help.

  • #14 / Jan 02, 2009 12:46pm

    Ingmar

    29245 posts

    Glad to see Derek was able to help you out there. Please post again if you need help again 😉

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases