Hoi,
Ik ben aan het leren om te gaan met OOP, maar ik liep tegen een probleempje aan. Ik wil dat een klein beetje gegevens zichtbaar wordt voor andere gebruikers, dat achterwege: alle data komt achterelkaar in een table.
Nu wil ik dat alle data weer in een volgende column komt.
Code:
Index.php
PHP-code:
<?php
require 'inc/user.class.php';
require 'inc/raintpl.class.php';
$con = new mysqli("localhost", "root", "Hacker :P", "login");
include "inc/rain.tpl.class.php";
raintpl::configure("tpl_dir", "tpl/" );
raintpl::configure("cache_dir", "tmp/" );
$user = new user($con);
//$user->getUsers();
//$user->getUsersWith("id", "1");
$tpl = new RainTPL;
$user->getUsers('rank');
$tpl->assign('name', $user);
$html = $tpl->draw('page');
echo $html;
?>
Die page.html dan:
PHP-code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>User { OOP + TPL }</title>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/bootstrap.css">
<script src="js/bootstrap.js"></script>
</head>
<body>
<div class="container">
<h1> Een inlogsysteem. <small> OOP + TPL </small></h1>
<table class="table table-hover">
<tr>
<th>Gebruikersnaam</th>
<th>Realname</th>
<th>Rank</th>
</tr>
<tr>
<td>{$name->getUsers('username')}</td>
<td>{$name->getUsers['realname']}</td>
<td>{$name->getUsers['rank']}</td>
</tr>
</table>
</div>
</body>
</html>
De user.class.php (Nog een paar keer html ge-echo't, omdat ik misschien zo het probleem kon oplossen. Was niet het geval)
<?php
PHP-code:
class user {
protected $con;
public $sql;
public $output;
public function __construct($con) {
$this->con = $con;
if ($con->connect_errno) {
trigger_error("Mislukt om verbinding te maken met de database. Diverse functie's zullen niet goed werken.");
}
}
public function getUsers($what) {
$this->sql = $this->con->query(
"SELECT * FROM users"
);
while ($this->output = $this->sql->fetch_assoc()) {
echo $this->output[$what]. "<br />";
}
}
public function getUsersWith($output, $what, $is) {
$this->sql = $this->con->query(
"SELECT * FROM users
WHERE $what=$is"
);
while ($this->output = $this->sql->fetch_assoc()) {
echo $this->output[$output]. "<br />";
}
}
}
?>
Screen hoe het er nu uitziet:
http://prntscr.com/4qrnqs
Alvast Bedankt
2.074 views