<?php
/**
* @class NewsModel
* @behavior Model
* This is where you change the data loaded, ONLY fiddle with
* the query inside NewsModel::read()
*/
class NewsModel
{
private function read() {
$query = mysql_query("SELECT * FROM newz");
while($row = mysql_fetch_array($query,MYSQL_ASSOC)) {
$result[] = $row;
}
return $result;
}
function load() {
$this->data = $this->read();
return $this->data;
}
}
/**
* @class News
* @behavior Controller
* Dont fiddle with this
*/
class News
{
function __construct() {
$this->getModel()->load();
$this->getView()->init($this);
}
function render() {
return $this->getView()->render();
}
function getView() {
if(!$this->view) {
$this->view = new NewsView($this);
}
return $this->view;
}
function getModel() {
if(!$this->model) {
$this->model = new NewsModel();
}
return $this->model;
}
}
/**
* @class NewsView
* @behavior View
* This is where you change your layout. Only fiddle within NewsView::render()
*/
class NewsView
{
function init($ctrl) {
$this->ctrl = $ctrl;
}
function render() {
$m = $this->ctrl->getModel();
$data = $m->data;
$html = '<marquee onMouseover="this.stop()" OnMouseout="this.start()">';
foreach($data as $record) {
$html .= '<a href="#" style="margin: 0 20px;">'.$record['content'].'<i>'.date('d-m-Y',$record['created']).'</i></a>';
}
$html .= '</marquee>';
return print $html;
}
}
// This is your database connection
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('local');
// Example 1
$n = new News();
$n->render();
// Example 2
/*
<div style="text-align: center;">
<div style="background:url('img/overskrift_bg.jpg') repeat-x; width:878px; height:30px; margin: 0 auto; text-align: left;">
<div style="position:relative; line-height:30px;">
<?php
$n = new News();
$n->render();
?>
<img src="img/marquee_left.png" style="position:absolute; top:0px; left:0px; bottom:0px; width:205px; height:30px;" />
<img src="img/marquee_right.png" style="position:absolute; top:0px; right:0px; bottom:0px; width:30px; height:30px;" />
</div>
</div>
</div>
*/
?>
Nærmere er der ikke nogen der kan hjælpe dig. Mit eksempel er blot en avanceret udgave af det der står ovenover. Men man er nødt til at lære at træde i pedallerne før man lærer at cykle.