Welcome Guest, Not a member yet? Register   Sign In
php mod % 3
#14

[eluser]John_Betong[/eluser]
 
Controller: news.php
Code:
//========================================================  
  function _dummy_data() {
    $image = "<img
              src='/ci_jokes/views/pink_161x178.jpg'
              style='width:42px; margin:0 auto 1em 1em' alt='I&rsquo;m going Pink for October' />";
    
    $result = array();
    
    for($i2=0; $i2<9; $i2++) {
      $result[] = array(
                        $i2,
                        'title: ' .$i2,
                        'author: ' .$i2,
                        'date: ' .$i2,
                        $image,
                        $image,
                        $image
                       );
    }
    return $result;
  }    
    
  //========================================================  
  function index($data=array())  {
    $content = $this->_dummy_data();
    
    $total_content = count($content);
    
    for($i2=0; $i2<$total_content; $i2++){
      switch($i2 % 3) {
            case 0 :  $data['a0'][] = $content[$i2];  break;
            case 1 :  $data['a1'][] = $content[$i2];  break;
            case 2 :  $data['a2'][] = $content[$i2];  break;
      }//endswitch      
    }//endfornext14:44 10/10/2008;

    $data['footer'] = $this->load->view('_footer',  $data, TRUE);
    $output         = $this->load->view('_NEWS',    $data, TRUE);
    echo $output;
  }//endfunc
&nbs;
view: _NEWS.php
Code:
...
...
  <div style='width:860px; height:666px; margin:0 auto; clear:both; scroll:auto; background:#fff none; color:#000; font-weight:bold'>
  
    <div id='box_left' style='float:left'>
      <a href='http://pinkforoctober.org/'>
        <img src='/ci_jokes/views/pink_161x178.jpg' style='width:132px; margin:0 auto 1em 1em' alt='I&rsquo;m going Pink for October' />
      </a>
    </div>  
    
    <div style='width:500px; margin:1em auto 14em; scroll:auto; border:solid 1px #ddd'>
      <div style='float:left; width:30%; margin:1em auto 0 1em; border:solid 1px #aaa'>
        &lt;?= show_contents($a0) ?&gt;
      </div>
      
      <div style='float:left; width:30%; margin:1em auto 0 1em; border:solid 1px #bbb'>
        &lt;?= show_contents($a1) ?&gt;
      </div>

      <div style='float:left; width:30%; margin:1em auto 0 1em; border:solid 1px #ccc'>
        &lt;?= show_contents($a2) ?&gt;
      </div>
    </div>  
    
    <div style='clear:both; width:860px; float:left; background:#f99 none; border:solid 1px #aaa'>
     &lt;?= $footer ?&gt;
    </div>

  </div>&lt;!-- container --&gt;  
...
...
&nbsp;
&nbsp;
Just noticed the array_chunk(...) function. that is going to save me repetitious coding.
&nbsp;
http://johns-jokes.com/news/index/
&nbsp;
&nbsp;
&nbsp;


Messages In This Thread
php mod % 3 - by El Forum - 10-18-2007, 06:07 PM
php mod % 3 - by El Forum - 10-18-2007, 08:01 PM
php mod % 3 - by El Forum - 10-18-2007, 10:00 PM
php mod % 3 - by El Forum - 10-18-2007, 10:07 PM
php mod % 3 - by El Forum - 10-19-2007, 03:31 AM
php mod % 3 - by El Forum - 10-29-2007, 04:04 PM
php mod % 3 - by El Forum - 10-31-2007, 05:24 AM
php mod % 3 - by El Forum - 10-31-2007, 08:23 AM
php mod % 3 - by El Forum - 10-31-2007, 09:03 AM
php mod % 3 - by El Forum - 10-09-2008, 04:07 PM
php mod % 3 - by El Forum - 10-09-2008, 09:06 PM
php mod % 3 - by El Forum - 10-09-2008, 11:17 PM
php mod % 3 - by El Forum - 10-10-2008, 12:34 AM
php mod % 3 - by El Forum - 10-10-2008, 03:38 AM
php mod % 3 - by El Forum - 10-10-2008, 12:23 PM
php mod % 3 - by El Forum - 10-11-2008, 09:36 AM
php mod % 3 - by El Forum - 10-11-2008, 01:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB