presentation logic for presenting categorized data nicely

From: Date: Sun, 07 Dec 2003 21:26:24 +0000
Subject: presentation logic for presenting categorized data nicely
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10645@lists.php.net to get a copy of this message
Hi Newsgroup I have a problem which must have been solved lots of times before and I'm looking for the most "correct" and "nice/neat" solution out there... I have two database-tables containing elements (link categories) and subelements (actual links) - More precisely I have the following db-structure (with sample data): <sql> CREATE TABLE linkcategories ( id int(3) unsigned NOT NULL auto_increment, category varchar(255) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM; INSERT INTO linkscat VALUES (1, 'Link Category 1'); INSERT INTO linkscat VALUES (2, 'Link Category 2'); CREATE TABLE links ( id tinyint(3) unsigned NOT NULL auto_increment, catid tinyint(3) unsigned NOT NULL default '0', //references id in category table url varchar(255) NOT NULL default '', title varchar(255) NOT NULL default '', description text NOT NULL, PRIMARY KEY (id) ) TYPE=MyISAM; INSERT INTO links VALUES (1, 2, 'URL1', 'TITLE1', 'DESCRIPTION1'); INSERT INTO links VALUES (2, 1, 'URL2', 'TITLE2', 'DESCRIPTION2'); INSERT INTO links VALUES (3, 2, 'URL3', 'TITLE3', 'DESCRIPTION3'); </sql> I need to create the following output from the above data: <output> Link Category 1: - title2, url2, description2 Link Category 2: - title1, url1, description1 - title3, url3, description3 </output> Since I would like the actual presentation of the links and categories to be configurable by the web designer I need to put some presentation logic into my smarty template. I'm a bit unsure how to solve this problem the "easiest" or most "correct" way. - Should the data be fetched seperately or simultaneously from the database? - Should I use some kind of nested loop structure or just one loop? I hope you can help me out here - surely this must be a "standard" problem? Thanks in Advance, Tommy Ipsen

« previous php.smarty.general (#10645) next »