Jump to content

Archived

This topic is now archived and is closed to further replies.

homchz

Repeating a Pattern

Recommended Posts

While creating my blog I have stumbled opun a problem.

I want to keep the code and the design seperate for the most part so I am trying to do this:

Post Function:
[code]
function blog_index()
        {
            $this->table = "blog_posts";
            $this->query = mysql_query("SELECT * FROM $this->table ORDER BY 'id' DESC");
        
            if(mysql_num_rows($this->query) > "0")
            {
                while($this->result = mysql_fetch_array($this->query))
                {
                    global $topic, $cat1, $cat2, $post, $img, $image_text, $date, $count;
                    
                    $topic = $this->result['topic'];
                    $cat1  = $this->result['category1'];
                    $cat2  = $this->result['category2'];
                    $post  = nl2br($this->result['post']);
                    $img   = $this->result['image'];
                    $image_text = $this->result['image_text'];
                    $date = $this->result['date'];
                    $count = count($this->result['id']);
                    
                    
                }
            }
        }
[/code]

Then the function is called in the index page where the design template is called, the template looks like this

[code]
<div id="left_col">
        <h2 class="blog_header"><?php print $topic ?></h2>
        <h3 class="blog_date"><?php print $date ?></h3>
        <p><?php print $post ?></p>
</div>
[/code]

As you see I call the global variables within the template, but as you can also guess there is no repeating region, so it will only print the first record.

I want to try and keep all the design info in the template and only call my variables when i need them. Is this possible??

Thanks for any info,

Josh

Share this post


Link to post
Share on other sites
I know you're trying to keep the code and the content separate, but you are going to need your loop in your display file. You should load up arrays with the info you need and then loop through them in your display file.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]

Share this post


Link to post
Share on other sites
[a href=\"http://smarty.php.net/\" target=\"_blank\"]Smarty[/a] is a common solution to this problem. With it, you can write design code such as:

[code]<table>
{foreach from=$my_array item=$row}
  <tr>
    <td>{$row.item1}</td>
    <td>{$row.item2}</td>
  </tr>
{/foreach}
</table>[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=373938:date=May 15 2006, 03:19 AM:name=btherl)--][div class=\'quotetop\']QUOTE(btherl @ May 15 2006, 03:19 AM) [snapback]373938[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[a href=\"http://smarty.php.net/\" target=\"_blank\"]Smarty[/a] is a common solution to this problem. With it, you can write design code such as:

[code]<table>
{foreach from=$my_array item=$row}
  <tr>
    <td>{$row.item1}</td>
    <td>{$row.item2}</td>
  </tr>
{/foreach}
</table>[/code]
[/quote]

That is pretty much what I said above. Except now you are telling them to use Smarty and learn another syntax.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]

Share this post


Link to post
Share on other sites

×

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.