Jump to content

Wondering why smarty is not looping through my code


cranberry13

Recommended Posts

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.

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.