[eluser]Callista[/eluser]
Hi,
for my job i'm making a news/blog page.
on the top it show 3 tables.
first table had 6 titles of the last 6 messages.
second table has 5 months in it with the number of messages written in that month behind it
Last table has de 6 most populair tags.
I got every thing working but the code for the months is a little bit big and messy. So i was wandering if anyone had an idea how i could get this cleaner.
CONTROLLER
Code: function template_2($pagina_ID)
{
$count_all_news = $this->Basis_model->count_all_nieuws();
$this_year = "'".date('y', mktime(0,0,0,date("m"),date("d"),date("Y")));
$month_01 = date('m', mktime(0,0,0,date("m"),date("d"),date("Y")));
$month_02 = date('m', mktime(0,0,0,($month_01-1),date("d"),date("Y")));
$month_03 = date('m', mktime(0,0,0,($month_01-2),date("d"),date("Y")));
$month_04 = date('m', mktime(0,0,0,($month_01-3),date("d"),date("Y")));
$month_05 = date('m', mktime(0,0,0,($month_01-4),date("d"),date("Y")));
$that_year = $this->get_that_year($month_01, $month_02, $month_03, $month_04, $month_05);
$monthname = $this->get_month_name();
$data['showmonth_01'] = $monthname[$month_01]." (". $this->Basis_model->count_month_01($month_01, $this_year).")";
$data['showmonth_02'] = $monthname[$month_02]." (". $this->Basis_model->count_month_02($month_02, $that_year).")";
$data['showmonth_03'] = $monthname[$month_03]." (". $this->Basis_model->count_month_03($month_03, $that_year).")";
$data['showmonth_04'] = $monthname[$month_04]." (". $this->Basis_model->count_month_04($month_04, $that_year).")";
$data['showmonth_05'] = $monthname[$month_05]." (". $this->Basis_model->count_month_05($month_05, $that_year).")";
$data['archief'] = $count_all_news;
$this->load->view('basis/template2', $data);
}
function get_that_year($maand_01, $maand_02, $maand_03, $maand_04, $maand_05)
{
$this_year = date('y', mktime(0,0,0,date("m"),date("d"),date("Y")));
if ($maand_02 > $maand_01){$that_year = "'".date('y', mktime(0,0,0,date("m"),date("d"),($this_year-1)));}
if ($maand_03 > $maand_01){$that_year = "'".date('y', mktime(0,0,0,date("m"),date("d"),($this_year-1)));}
if ($maand_04 > $maand_01){$that_year = "'".date('y', mktime(0,0,0,date("m"),date("d"),($this_year-1)));}
if ($maand_05 > $maand_01){$that_year = "'".date('y', mktime(0,0,0,date("m"),date("d"),($this_year-1)));}
else{$that_year = "'".date('y', mktime(0,0,0,date("m"),date("d"),date("Y")));}
return $that_year;
}
function get_maand_naam()
{
$maandnaam = array('01' => 'Januari','02' => 'Februari','03' => 'Maart','04' => 'April','05' => 'Mei','06' => 'Juni','07' => 'Juli',
'08' => 'Augustus','09' => 'September','10' => 'Oktober','11' => 'November','12' => 'December');
return $maandnaam;
}
MODEL
Code: function count_month_01($month_01, $this_year)
{
$this->db->select('nieuws_datum_maand');
$this->db->where("nieuws_status",1);
$this->db->where("nieuws_datum_maand",$month_01);
$this->db->where("nieuws_datum_jaar",$this_year);
$this->db->from('nieuws');
return $this->db->count_all_results();
}
function count_month_02($month_02, $that_year)
{
$this->db->select('nieuws_datum_maand');
$this->db->where("nieuws_status",1);
$this->db->where("nieuws_datum_maand",$month_02);
$this->db->where("nieuws_datum_jaar",$that_year);
$this->db->from('nieuws');
return $this->db->count_all_results();
}
function count_month_03($month_03, $that_year)
{
$this->db->select('nieuws_datum_maand');
$this->db->where("nieuws_status",1);
$this->db->where("nieuws_datum_maand",$maand_03);
$this->db->where("nieuws_datum_jaar",$that_year);
$this->db->from('nieuws');
return $this->db->count_all_results();
}
function count_month_04($month_04, $that_year)
{
$this->db->select('nieuws_datum_maand');
$this->db->where("nieuws_status",1);
$this->db->where("nieuws_datum_maand",$month_04);
$this->db->where("nieuws_datum_jaar",$that_year);
$this->db->from('nieuws');
return $this->db->count_all_results();
}
function count_month_05($month_05, $that_year)
{
$this->db->select('nieuws_datum_month');
$this->db->where("nieuws_status",1);
$this->db->where("nieuws_datum_maand",$month_05);
$this->db->where("nieuws_datum_jaar",$that_year);
$this->db->from('nieuws');
return $this->db->count_all_results();
}
VIEUW
Code: <div class="nieuwslist">
<ul>
<li><a href="#" class="list"><?php echo $toonmaand_01;?></a></li>
<li><a href="#" class="list"><?php echo $toonmaand_02;?></a></li>
<li><a href="#" class="list"><?php echo $toonmaand_03;?></a></li>
<li><a href="#" class="list"><?php echo $toonmaand_04;?></a></li>
<li><a href="#" class="list"><?php echo $toonmaand_05;?></a></li>
<li><?php echo "<a >Archief (".$archief.")</a></li>";?>
</ul>
</div>
This is just to much code for a simpel function but i have no idea or inspiration for a better construction.
Anyone have an idea?
|