Re: [SMARTY] How do I group db results by category with Smarty?
| From: | Tim Burden | Date: | Tue, 07 Jan 2003 00:25:10 +0000 |
| Subject: | Re: [SMARTY] How do I group db results by category with Smarty? | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7047@lists.php.net to get a copy of this message | ||
SELECT * FROM table1,table2 WHERE table1.cat_id = table2.cat_id AND text
LIKE $q GROUP BY table1.cat_id.
Then in the template, set $foo = '', loop through this result set, setting
$foo = $cat_id at the end of each iteration, then print cat_description if
$foo != $cat_id
would be one way.
----- Original Message -----
From: "gawan" <mail@gawan.net>
To: <smarty-general@lists.php.net>
Sent: Monday, January 06, 2003 6:33 PM
Subject: [SMARTY] How do I group db results by category with Smarty?
> I have a table with data and an other table with category information for
> the data
>
> table1: id, title, text, cat_id
> table2: cat_id, cat_description
>
> It is easy to display data from table 1 with smarty. I fetch the data as
an
> object array an display these with a smarty foreach loop.
> But I don't know how to display the data organized by category and use the
> gategory name (cat_description as a caption for each group).
> (The number of categories in each case after a search is unknown, as are
the
> number of rows in each gategory, if any)
> Does anyone know an example of using Smarty to display hierarcical data
this
> way. I was hoping to render the data like this:
>
> Caption for category one (from cat_description)
> A row of data
> A row of data
> A row of data
> Caption for category two
> A row of data
> A row of data
> A row of data
> Caption for category three
> A row of data
> A row of data
> A row of data
> :
> etc
>
> Any advise on how to start tackling this challence?
> thank you very much
>
> gawan
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>