|
Re: [SMARTY] How do I group db results by category with Smarty?: msg#00261php.smarty.general
If you look at the bottom of my original post, you'll se what I aimed. I wanted to use two tables in a master detail relationship and print my datarows in sections and caption inserted between each section. The example in my last post prints data correctly but prints a caption (or a subheader) above each row instead of printing only when genre_id has changed. Nothing to do with order by or group by clauses, I think. gawan ----- Original Message ----- From: "Hoffman, Geoffrey" <ghoffman@xxxxxxxxxx> To: "Smarty (E-mail)" <smarty-general@xxxxxxxxxxxxx> Sent: Thursday, January 16, 2003 10:41 PM Subject: RE: [SMARTY] How do I group db results by category with Smarty? Does your SQL query have ORDER BY or GROUP BY working properly? If not, { look at the examples here: http://www.mysql.com/doc/en/SELECT.html } else { What do you want to do? For instance, colorize the groups with a different cell color? I'm confused. } ----- Original Message ----- From: "gawan" <mail@xxxxxxxxx> To: <smarty-general@xxxxxxxxxxxxx> Sent: Thursday, January 16, 2003 9:40 PM Subject: Re: [SMARTY] How do I group db results by category with Smarty? > I finally got time get back to this problem. > > I tried something like this (cat_id is here genre_id and cat_description is > genre_description): > > {$foo eq ''} > {foreach from=$db_result item=current key=PISBN} > <tr> > <td colspan="10">{if $foo ne > $current->genre_id}{$current->genre_description}{/if}</td> > </tr> > <tr> > <!- printing row data here --> > </tr> > {$foo eq $current->genre_id} > {/foreach} > > I kind of see why this will not work, but I can't figure out how this should > be written...!? > > thanks for any further advice > > gawan > > ----- Original Message ----- > From: "Tim Burden" <tim@xxxxxxxxxxxxxx> > To: "gawan" <mail@xxxxxxxxx>; <smarty-general@xxxxxxxxxxxxx> > Sent: Tuesday, January 07, 2003 2:25 AM > Subject: Re: [SMARTY] How do I group db results by category with Smarty? > > > > 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@xxxxxxxxx> > > To: <smarty-general@xxxxxxxxxxxxx> > > 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 > > > > > > > > > -- > > Smarty General Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: [SMARTY] How do I group db results by category with Smarty?: 00261, Kelly Cochran |
|---|---|
| Next by Date: | Re: [SMARTY] How do I group db results by category with Smarty? - a solution: 00261, gawan |
| Previous by Thread: | Re: [SMARTY] How do I group db results by category with Smarty?i: 00261, gawan |
| Next by Thread: | Re: [SMARTY] How do I group db results by category with Smarty? - a solution: 00261, gawan |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | Mail Home | sitemap | FAQ | advertise |