homchz Posted May 15, 2006 Share Posted May 15, 2006 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 Quote Link to comment Share on other sites More sharing options...
jeremywesselman Posted May 15, 2006 Share Posted May 15, 2006 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--] Quote Link to comment Share on other sites More sharing options...
btherl Posted May 15, 2006 Share Posted May 15, 2006 [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 Link to comment Share on other sites More sharing options...
jeremywesselman Posted May 15, 2006 Share Posted May 15, 2006 [!--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--] Quote Link to comment 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.