TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 03-16-2009, 12:29 AM   #1 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default 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>";
?>
hello-world is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tips to Improve Your Coding and Projects Village Idiot Tips & Tricks 45 12-03-2012 07:46 AM
Writing Clean Code Village Idiot Tips & Tricks 10 06-25-2012 12:35 PM
How good is my coide geo353 Advanced PHP Programming 3 12-22-2008 07:39 PM
Good business communication. Village Idiot The Lounge 10 01-11-2008 08:43 PM
Coding nicely Tanax General 3 12-05-2007 05:20 PM


All times are GMT. The time now is 08:22 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design