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.

Is it possible to keep {total_results} from repeating?

March 07, 2010 8:51pm

Subscribe [2]
  • #1 / Mar 07, 2010 8:51pm

    Patrick Mc

    19 posts

    I’d like to display the total results of a query but it repeats for each result.

    {exp:query sql="SELECT vehicles.make, vehicles.model FROM vehicles WHERE vehicles.make = 'Subaru'}
                              
    <div class="infomessage">{total_results} Vehicles Match Your Search</div>
        
    {/exp:query}


    If the query turns out 7 results, it display ‘7 7 7 7 7 7 7’. Is it possible to keep {total_results} from repeating?

    Thanks for any help or suggestions.

  • #2 / Mar 08, 2010 1:22am

    John Henry Donovan

    12339 posts

    Patrick

    Add a LIMIT to your tag. You are also missing a closing double apostrophe

    {exp:query sql="SELECT vehicles.make, vehicles.model FROM vehicles WHERE vehicles.make = 'Subaru' LIMIT 1"}
                              
    <div class="infomessage">{total_results} Vehicles Match Your Search</div>
        
    {/exp:query}
  • #3 / Mar 08, 2010 9:55pm

    Patrick Mc

    19 posts

    Thank you for the help.

    I did add a limit but then the total ended up being whatever I set my limit to. For anyone else who has the same issue, I found the solution in this thread, which had to do with utilizing the COUNT function in your sql statement.

    {exp:query sql="SELECT COUNT(vehicles.model) AS total_vehicles FROM vehicles WHERE vehicles.make = 'Subaru'"}
                              
       <div class="infomessage">{total_vehicles} Vehicles Match Your Search</div>
        
    {/exp:query}

    😊

  • #4 / Mar 09, 2010 1:31am

    John Henry Donovan

    12339 posts

    Ah yes. My bad. Should have known that. Glad you got it working . Feel free to start a new thread if you have any more questions.

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

ExpressionEngine News!

#eecms, #events, #releases