TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Good or Bad Code (http://www.talkphp.com/absolute-beginners/4042-good-bad-code.html)

hello-world 03-16-2009 12:29 AM

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>";
?>


Wildhoney 03-16-2009 01:04 AM

It looks like fairly good code to me. I understand what is happening, and that's a huge plus.


All times are GMT. The time now is 04:44 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0