cranberry13 Posted January 29, 2008 Share Posted January 29, 2008 I have a template that I modifed and I want it to loop through the DB search results. It's not working though. Here is what I have: 1) in the template: {foreach name=blog from=$m2m->getTopNewsBlog() key=blog_id item=blog} <div> <img src="/images/blogs/{$blog.blog_id}.jpg" style="display:inline; float:left; padding-right:5px" /> <div class="spotlight_headline"><a href="/forum/memberlist.php?mode=viewprofile&u={$blog.blogger_id}&t=blog&blog_id={$blog_id}">{$blog.title}</a></div> <div class="spotlight_body"><br /> blogid:{$blog.blog_id}<br> blogger id:{$blogger_id}<br> blog:{$blog.blog}<br> titel:{$blog.title}<br> {$blog.blog|strip_tags|truncate:"350":"..."} - <a href="/forum/memberlist.php?mode=viewprofile&u={$blog.blogger_id}&t=blog&blog_id={$blog.blog_id}"><span class="underline">read more</span></a> </div> </div> {/foreach} 2. in the lib file where the function is declared: public function getTopNewsBlog() { $sql = 'select b.blogger_id, b.blog_id, b.title,b.blog from blogs b where blogger_id=2 limit 5'; return $this->runQuery('getAssoc',$sql); } 3. And this is the table declaration mysql> describe blogs; +---------------+----------------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------------------+------+-----+---------------------+----------------+ | blog_id | mediumint(9) | NO | PRI | NULL | auto_increment | | blogger_id | mediumint(9) | NO | MUL | 0 | | | title | varchar(255) | NO | | NULL | | | blog | text | NO | | NULL | | | photo | tinyint(1) | NO | MUL | 0 | | | photo_caption | varchar(255) | NO | | NULL | | | photo_align | tinyint(1) unsigned | NO | | 2 | | | submitted_on | datetime | NO | | 0000-00-00 00:00:00 | | | views | smallint(5) unsigned | NO | | 0 | | +---------------+----------------------+------+-----+---------------------+----------------+ 9 rows in set (0.00 sec) When I run the query from the command line I get two results. However, on my webpage only one of the results is being printed. I've been banging my head on this for 3 hours and am at a loss as to what to do. I've tried a key with 'blog_id' and 'blogger_id' and that didn't fix anything. Why is this not working? I am at my job right now and there is a lot of pressure to finish this today. I have used php but I am new to smarty. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/88394-wondering-why-smarty-is-not-looping-through-my-code/ Share on other sites More sharing options...
cranberry13 Posted January 29, 2008 Author Share Posted January 29, 2008 Sorry about that - i'm reposting this with code tags. Thanks. --------------------------------------------------- I have a template that I modifed and I want it to loop through the DB search results. It's not working though. Here is what I have: 1) in the template: {foreach name=blog from=$m2m->getTopNewsBlog() key=blog_id item=blog} <div> <img src="/images/blogs/{$blog.blog_id}.jpg" style="display:inline; float:left; padding-right:5px" /> <div class="spotlight_headline"><a href="/forum/memberlist.php?mode=viewprofile&u={$blog.blogger_id}&t=blog&blog_id={$blog_id}">{$blog.title}</a></div> <div class="spotlight_body"><br /> blogid:{$blog.blog_id}<br> blogger id:{$blogger_id}<br> blog:{$blog.blog}<br> titel:{$blog.title}<br> {$blog.blog|strip_tags|truncate:"350":"..."} - <a href="/forum/memberlist.php?mode=viewprofile&u={$blog.blogger_id}&t=blog&blog_id={$blog.blog_id}"><span class="underline">read more</span></a> </div> </div> {/foreach} 2. in the lib file where the function is declared: public function getTopNewsBlog() { $sql = 'select b.blogger_id, b.blog_id, b.title,b.blog from blogs b where blogger_id=2 limit 5'; return $this->runQuery('getAssoc',$sql); } 3. And this is the table declaration mysql> describe blogs; +---------------+----------------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------------------+------+-----+---------------------+----------------+ | blog_id | mediumint(9) | NO | PRI | NULL | auto_increment | | blogger_id | mediumint(9) | NO | MUL | 0 | | | title | varchar(255) | NO | | NULL | | | blog | text | NO | | NULL | | | photo | tinyint(1) | NO | MUL | 0 | | | photo_caption | varchar(255) | NO | | NULL | | | photo_align | tinyint(1) unsigned | NO | | 2 | | | submitted_on | datetime | NO | | 0000-00-00 00:00:00 | | | views | smallint(5) unsigned | NO | | 0 | | +---------------+----------------------+------+-----+---------------------+----------------+ 9 rows in set (0.00 sec) When I run the query from the command line I get two results. However, on my webpage only one of the results is being printed. I've been banging my head on this for 3 hours and am at a loss as to what to do. I've tried a key with 'blog_id' and 'blogger_id' and that didn't fix anything. Why is this not working? I am at my job right now and there is a lot of pressure to finish this today. I have used php but I am new to smarty. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/88394-wondering-why-smarty-is-not-looping-through-my-code/#findComment-452381 Share on other sites More sharing options...
cranberry13 Posted January 29, 2008 Author Share Posted January 29, 2008 Just an additional note that two items are returned by the database. Only one item is displayed on the webpage though. Can anyone help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/88394-wondering-why-smarty-is-not-looping-through-my-code/#findComment-452401 Share on other sites More sharing options...
cranberry13 Posted January 29, 2008 Author Share Posted January 29, 2008 Please...can someone help me with this. I am really stuck. Quote Link to comment https://forums.phpfreaks.com/topic/88394-wondering-why-smarty-is-not-looping-through-my-code/#findComment-452445 Share on other sites More sharing options...
cranberry13 Posted January 29, 2008 Author Share Posted January 29, 2008 Help! Quote Link to comment https://forums.phpfreaks.com/topic/88394-wondering-why-smarty-is-not-looping-through-my-code/#findComment-452554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.