03-16-2009, 12:29 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Feb 2009
Posts: 73
Thanks: 30
|
Good or Bad Code
Can you please take look at these to 3 files.
though I get the result I want,I am not sure it is a good or Bad Code.
PHP Code:
<?php
/*
* File:menu.cls.php
* Folder:classes
*
*/
require("includes/configs.php");
class Menu {
public $result;
public $connDB;
public function __construct(){
global $config;
$host = $config['db']['host'];
$user = $config['db']['user'];
$pass = $config['db']['pass'];
$this->connDB = new PDO($host,$user,$pass);
}
public function showMenu(){
$conn = $this->connDB->query("select * from menu");
while($res = $conn->fetch(PDO::FETCH_ASSOC)){
$this->result[] = $res;
}
$this->result;
}
}
?>
PHP Code:
<?php
/*
* File:config.php
* Folder:includes
*
*/
$config['db']['host'] = "mysql:host=localhost;dbname=gry";
$config['db']['user'] = "root";
$config['db']['pass']="";
$config['site']['name'] = "Gallery";
?>
PHP Code:
<?php
/*
* File:index.php
* Folder:root
*/
require("classes/menu.cls.php");
$new = new Menu;
$new->showMenu();
echo "<ul style=padding=50px>";
foreach ($new->result as $key){
echo "<li style=display:inline;padding:5px;text:none;><a href='".$key['url']."'>\t".$key['name']."</a></li>";
}
echo "</ul>";
?>
|
|
|
|