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.

Query and pagination not working

March 10, 2009 1:11pm

Subscribe [3]
  • #1 / Mar 10, 2009 1:11pm

    CimexMedia

    68 posts

    Is it normal that the paginate tags don’t work with any non-trivial SQL query ?

    here’s what I have, the pagination do not work

    {exp:query limit="15" paginate="both" sql="
    SELECT t.entry_id as supplier_id, t.title as supplier_name, t.url_title as supplier_url_title, t.entry_id as supplier_id, 
    d.field_id_108 as supplier_logo, d.field_id_13 as supplier_address1,d.field_id_34 as supplier_address2,d.field_id_35 as supplier_town,
    d.field_id_37 as supplier_county,d.field_id_36 as supplier_postal_code,d.field_id_38 as supplier_country, d.field_id_14 as supplier_telephone, 
    d.field_id_15 as supplier_fax, d.field_id_16 as supplier_email, d.field_id_17 as supplier_website1, d.field_id_12 as supplier_profile, MIN(p.cat_id) as min_cat_id
    
    FROM exp_weblog_data as d, exp_weblog_titles as t, exp_category_posts as p
    WHERE t.weblog_id = '8' 
    AND t.site_id = '1' 
    AND t.entry_id = d.entry_id 
    AND t.title REGEXP '^A'
    AND d.entry_id = p.entry_id 
    GROUP BY t.entry_id
    ORDER BY t.title ASC
    "}
    
    {if count == 1}
        <ul>
    {/if}
    <li class="supplier-line">
        <h3>{supplier_name}</h3>
    
    <p>    <div class="left"><br />
         {embed="buyers_guide/supplier_logo" logo_code="{supplier_logo}"}<br />
         <address class="details-enhanced"><br />
             {if supplier_address1}{supplier_address1}<br />
    {/if}<br />
             {if supplier_address2}{supplier_address2}<br />
    {/if}<br />
             {if supplier_town}{supplier_town}<br />
    {/if}<br />
             {if supplier_county}{supplier_county}<br />
    {/if}<br />
             {if supplier_postal_code}{supplier_postal_code}<br />
    {/if}<br />
             {if supplier_country}{supplier_country}<br />
    {/if}<br />
         </address><br />
             <br />
        </div><br />
        <div class="right"><br />
            <a href="http://{path=buyers_guide/supplier_page/}{supplier_url_title}class=view-profile">View Full Profile</a><br />
        </div><br />
    </li></p>
    
    <p>{if count == total_results}<br />
        </ul><br />
    {/if}</p>
    
    <p>{paginate}<br />
        <span class="letter">{segment_3}</span><!-- Page {current_page} of {total_pages} pages  --><span class="number-links">{pagination_links}</span><br />
    {/paginate}<br />
    {/exp:query}


    I would gladly use $DB to query but I stuck with exp:query in the hope that I could use the built-in pagination

    How can I paginate if I query $DB directly ?

    Thanks

  • #2 / Mar 10, 2009 5:02pm

    Ingmar

    29245 posts

    Have you considered using a plugin for pagination?

  • #3 / Mar 11, 2009 9:10am

    CimexMedia

    68 posts

    No, I did not know about this. Thanks for pointing this out

    Any explanation as to why my query breaks pagination when used with exp:query ?

    Thanks

  • #4 / Mar 11, 2009 1:24pm

    Sue Crocker

    26054 posts

    CimexMedia, if you change the items in the middle of your query to be something like this:

    {supplier_name}<br>
      {paginate}
        Page {current_page} of {total_pages} pages {pagination_links}
      {/paginate}

    Does pagination work then?

  • #5 / Mar 13, 2009 7:03am

    CimexMedia

    68 posts

    I have tried this :

    {exp:query limit="15" paginate="both" sql="
            SELECT t.entry_id as supplier_id, t.title as supplier_name, t.url_title as supplier_url_title, t.entry_id as supplier_id, 
            d.field_id_108 as supplier_logo, d.field_id_13 as supplier_address1,d.field_id_34 as supplier_address2,d.field_id_35 as supplier_town,
            d.field_id_37 as supplier_county,d.field_id_36 as supplier_postal_code,d.field_id_38 as supplier_country, d.field_id_14 as supplier_telephone, 
            d.field_id_15 as supplier_fax, d.field_id_16 as supplier_email, d.field_id_17 as supplier_website1, d.field_id_12 as supplier_profile, MIN(p.cat_id) as min_cat_id
    
            FROM exp_weblog_data as d, exp_weblog_titles as t, exp_category_posts as p
            WHERE t.weblog_id = '8' 
            AND t.site_id = '1' 
            AND t.entry_id = d.entry_id 
            AND t.title REGEXP '^A'
            AND d.entry_id = p.entry_id 
            GROUP BY t.entry_id
            ORDER BY t.title ASC
            "}
    
    
            {if no_results}
            Sorry, we have no supplier whose name starts with {if segment_3 == 0 }a digit{if:else}{segment_3}{/if} !
            {/if}
            
            {if count == 1}
            <ul>
            {/if}
            <li class="supplier-line{if min_cat_id == 8} supplier-enhanced{/if}">
                {supplier_name}
            </li>
            {paginate}
            Page {current_page} of {total_pages} pages {pagination_links}
          {/paginate}
            
                
            </li>
            {if count == total_results}
            </ul>
            {/if}
            {paginate}
            <span class="letter">{segment_3}</span><!-- Page {current_page} of {total_pages} pages  --><span class="number-links">{pagination_links}</span>
            
            {/paginate}
            {/exp:query}

    I does not work either :(

  • #6 / Mar 13, 2009 12:25pm

    Ingmar

    29245 posts

    I’d suggest some template reduction. Start with a minimal sample, and build complexity from there. The query module is made for rather simple, “SELECT” type queries. For complex queries like yours, using the database class might indeed be preferable.

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

ExpressionEngine News!

#eecms, #events, #releases