<?php /*** voorbeeldpagina1.php ***/
require('connect.php');
include('classes.php');

$where1 = "wedstrijden.id = '92'";

// 1 wedstrijd tonen met bijhorende verslagen
$w1 = new wedstrijden($where1);
if($w1->toon_wedstrijd()){
	echo '<p>'. $w1->wedstrijd['datum'] .' '. $w1->wedstrijd['tijd'] .'<br>'. $w1->wedstrijd['ploegen'] .'</p>';
	while($w1->toon_verslag()){
		echo '<p><b>'.$w1->verslag['onderwerp'].'</b> ('.$w1->verslag['member_link'].')<br>';
		echo ubb_code($w1->verslag['tekst']).'</p>';
	}
}else{
	echo 'Wedstrijd niet gevonden';
}
$w1->destroy(true);
?>

<?php /*** voorbeeldpagina2.php ***/
require('connect.php');
include('classes.php');

$where2 = array("datum < NOW() AND  pid ='".$ploeg['id']."'","datum >= NOW() AND pid ='".$ploeg['id']."'");
$limit2 = array(15,10);


// wedstrijdenlijst weergeven
$wedstrijden2 = new wedstrijden($where2,$limit2);
echo $wedstrijden2->toon_lijst();
$wedstrijden2->destroy(true);
?>

<?php /*** voorbeeldpagina3.php ***/
require('connect.php');
include('classes.php');

$where2 = array("datum < NOW() AND  pid ='".$ploeg['id']."'","datum >= NOW() AND pid ='".$ploeg['id']."'");
$limit2 = array(15,10);


// wedstrijden weergeven zonder html uitvoer van de klasse
$w3 = new wedstrijden($where2,$limit2);
if($w3->rows >= 1){
	while($w3->toon_wedstrijd()){
		echo $w3->debug($w3->wedstrijd); // array wedstrijd tonen
		while($w3->toon_verslag(){
			echo $w3->debug($w3->verslag); //array verslag tonen
		}
	}
}else{
	echo 'Geen wedstrijden gevonden';
}
$w3->destroy(true);
?>

<?php /*** dit is classes.php ***/
$site['url'] = 'http://www.westsite.be'; //zonder een / op het einde
class wedstrijden {

	var $result;
	var $rows;
	var $lijst = array();
	var $wedstrijd = array();
	var $verslag = array();
	
	function wedstrijden($where,$limit = 0){
		$where = $this->maak_array($where);
		$limit = $this->maak_array($limit);
		
		if(count($where) >= count($limit)){
			$this->rows = count($where) - 1;
		}else{
			return false;
		}
		
		$query .= '';
		
		for ($i = 0; $i <= $this->rows; $i++) {
			$query .= '
		(SELECT wedstrijden.*, ploegen.naam 
		FROM wedstrijden 
		INNER JOIN ploegen ON (wedstrijden.pid = ploegen.id)
		WHERE '.$where[$i].'
		ORDER BY datum DESC';

			if(!empty($limit[$i])){
				$query .= "\n".'		LIMIT '.$limit[$i];
			}
			
			$query .= ')';
			
			if($i < $this->rows){
				$query .= "\n".'		UNION ';
			}
		}
		
		$query .= "\n".'		ORDER BY datum ASC';
		
		$this->result = mysql_query($query);
		$this->rows   = mysql_num_rows($this->result);	

	}
	
	
	
	function toon_lijst(){
		global $site;
		
		if($this->rows >= 1){
			$this->lijst  = '<table border="0" cellspacing="8" cellpadding="2"><tr>'
							."\n";
			$this->lijst .= '<th><img src="'.$site['url'].'/images/icons/calendar.png" align="absmiddle">&nbsp;&nbsp;Datum</th>'."\n";
			$this->lijst .= '<th><img src="'.$site['url'].'/images/icons/clock.png" align="absmiddle">&nbsp;&nbsp;Tijd</th>'."\n";
			$this->lijst .= '<th><img src="'.$site['url'].'/images/icons/person.png" align="absmiddle">&nbsp;&nbsp;Tegenstander</th>'."\n";
			$this->lijst .= '<th><img src="'.$site['url'].'/images/icons/document.png" align="absmiddle">&nbsp;&nbsp;Score</th>'."\n";
			$this->lijst .= '<th><img src="'.$site['url'].'/images/icons/info.png" align="absmiddle">&nbsp;&nbsp;Info</th>'."\n";
			$this->lijst .= '<th><img src="'.$site['url'].'/images/icons/write.png" align="absmiddle">&nbsp;&nbsp;Verslagen</th></tr>'."\n";
			
			while($this->toon_wedstrijd()){
			$this->lijst .= '<tr>';
			$this->lijst .= '<td align="center">'.	$this->wedstrijd['datum']		.'</td>';
			$this->lijst .= '<td>om '.				$this->wedstrijd['tijd']		.'</td>';
			$this->lijst .= '<td align="center">'.	$this->wedstrijd['ploegen_link'].'</td>';
			$this->lijst .= '<td align="center">'.	$this->wedstrijd['score']		.'</td>';
			$this->lijst .= '<td align="center">'.	$this->wedstrijd['info']		.'</td>';
			$this->lijst .= '<td align="center">'.	$this->wedstrijd['verslag_link'].'</td>';
			}
			$this->lijst .= '</table>';
		}else{
			$this->lijst  = 'Geen wedstrijden gevonden';
		}
		return $this->lijst;
	}

	function toon_wedstrijd(){
		global $maand;
		global $date;
		$wedstrijd =  mysql_fetch_array($this->result);
		$this->wedstrijd = array();
		if($wedstrijd){
			$this->wedstrijd['id'] = $wedstrijd['id'];
		
			$this->wedstrijd['date'] = $wedstrijd['datum'];
			list($this->wedstrijd['datum'],$this->wedstrijd['tijd']) = explode(' ',$wedstrijd['datum']);
		
			$this->wedstrijd['datum'] = explode('-', $this->wedstrijd['datum']);
			$this->wedstrijd['datum'] = intval($this->wedstrijd['datum'][2]).' '.$maand[intval($this->wedstrijd['datum'][1])].' '.$this->wedstrijd['datum'][0];
	
			$this->wedstrijd['tijd'] = explode(":",$this->wedstrijd['tijd']);
			$this->wedstrijd['tijd'] = $this->wedstrijd['tijd'][0]."u".$this->wedstrijd['tijd'][1];
		
			$this->wedstrijd['ploeg_id'] = $wedstrijd['pid'];
			$this->wedstrijd['ploeg_naam'] = $wedstrijd['naam'];
			$this->wedstrijd['ploeg_link'] = '<a href="'.$site['url'].'/ploegen.php?id='.$wedstrijd['pid'].'" title="'.$wedstrijd['naam'].'">'.$wedstrijd['naam'].'</a>';
		
			$this->wedstrijd['tegenstander'] = $wedstrijd['tegenstander'];
			$this->wedstrijd['locatie'] = $wedstrijd['locatie'];
		
			if($wedstrijd['locatie'] == 'Thuis'){
				$this->wedstrijd['ploegen'] = $this->wedstrijd['ploeg_naam'] . ' - ' . $wedstrijd['tegenstander'];
				$this->wedstrijd['ploegen_link'] = $this->wedstrijd['ploeg_link'] . ' - ' . $wedstrijd['tegenstander'];
			}elseif($wedstrijd['locatie'] == 'Verplaatsing'){
				$this->wedstrijd['ploegen'] = $wedstrijd['tegenstander'] . ' - ' . $this->wedstrijd['ploeg_naam'];
				$this->wedstrijd['ploegen_link'] = $wedstrijd['tegenstander'] . ' - ' . $this->wedstrijd['ploeg_link'];
			}
		
			if($wedstrijd['info']){
				$this->wedstrijd['info'] = $wedstrijd['info'];
			}
			if($wedstrijd['score']){
				$this->wedstrijd['score'] = $wedstrijd['score'];
			}
			
			$this->wedstrijd['verslag']	 = mysql_query("SELECT verslagen.*, members.gebruikersnaam, members.avatar 
														FROM verslagen 
														JOIN members ON (members.id = verslagen.mid) 
														WHERE wid ='" . $this->wedstrijd['id'] . "'");
			
			$this->wedstrijd['verslag_aantal'] = mysql_num_rows($this->wedstrijd['verslag']);
			$this->wedstrijd['verslag_link'] = '<a href="'.$site['url'].'/wedstrijden.php?wid='.$this->wedstrijd['id'].'" title="'.$this->wedstrijd['ploegen'].'">';
			if($wedstrijd['datum'] < $date){
				$this->wedstrijd['verslag_link'] .= $this->wedstrijd['verslag_aantal'];
			}else{
				$this->wedstrijd['verslag_link'] .= '---';
			}
			$this->wedstrijd['verslag_link'] .= '</a>';
			
		}
		return $this->wedstrijd;
	}
	
	function toon_verslag(){
		global $site;
		$verslag =  mysql_fetch_array($this->wedstrijd['verslag']);
		$this->verslag = array();
		if($verslag){	
			$this->verslag['id'] = $verslag['id'];
		
			$this->verslag['date'] = $verslag['datum'];
		
			if($verslag['onderwerp']){
				$this->verslag['onderwerp'] = $verslag['onderwerp'];
			}
			$this->verslag['tekst'] 		= ubb_code($verslag['verslag']);
			
			$this->verslag['member_id'] 	= $verslag['mid'];
			$this->verslag['member_naam']	= $verslag['gebruikersnaam'];
			$this->verslag['member_link']	= '<a href="'.$site['url'].'/info.php?mid='.$verslag['mid'].'" title="'.$verslag['gebruikersnaam'].'">'.$verslag['gebruikersnaam'].'</a>';
			$this->verslag['member_avatar']	= $site['url'].$verslag['avatar'];
			$this->verslag['member_ip'] 	= $verslag['ip'];
			
		}
		return $this->verslag;
	}
	
	function maak_array($array){
		if(is_array($array)){
			return $array;
		}elseif(empty($array)){
			return false;
		}else{
			return array($array);
		}
	}

	function debug($array = false){
		if(!$array){ $array = $this; }
		return '<pre>'.print_r($array, true).'</pre>';
	}
	
	function destroy($destroy){
		if($destroy){
			unset($this->result,$this->rows,$this->lijst,$this->wedstrijd,$this->verslag);
		}
	}
	
}

?>

voor de n00bs:
<?php /*** dit is connect.php ***/

//logingegevens en standaard connectie met de database

$host = "localhost"; //meestal localhost 
$user = "user";  //gebruikersnaam
$pass = "****";  //wachtwoord
$db	  = "database";  //database selectie

$connection = mysql_connect( $host, $user, $pass ); 

// connectie gemaakt? 
if( $connection ) 
{ 
    // selecteer de database 
    if( !mysql_select_db( $db, $connection ) ) 
    { 
        // kon de database niet selcteren! 
        die('Kon de database niet selecteren! Error: ' . mysql_error() ); 
    } 
} 
// kon geen verbinding maken met de database 
else{ 
    die('<p>Kon geen verbinding maken met de database!</p><pre>Error('.mysql_errno().'): '. mysql_error() .'</pre>'); 
}  

?>