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 05-16-2008, 02:39 AM   #1 (permalink)
The Wanderer
 
Join Date: Dec 2007
Posts: 18
Thanks: 2
xperience is on a distinguished road
Default How to think OOP ?

PHP Code:
<?php

require 'libs/Smarty.class.php';
require 
'config/newsRoom.config';

$smarty = new Smarty;

$smarty->compile_check true;
$smarty->debugging false;

$dbc    mysqli_connect(HOSTUSERNAMEPASSWORDDATABASE);

/* Retrieve List of all news Articles */
$query  mysqli_query($dbc"SELECT * 
                                FROM " 
TABLE .
                                
" ORDER BY id DESC
                                LIMIT 10"
);
$result = array();
$i      0;

while (
$n mysqli_fetch_array($query)) {
    
$tmp = array(
                
'id'         => $n['id'],
                
'date'         => $n['date'],
                
'location'     => $n['location'],
                
'title'     => $n['title'],
                
'summary'     => $n['summary'],
                
'article'     => $n['article']);
                
$result[$i++] = $tmp;
}

if (
$_GET['article'] == NULL) {
    
$article     = (int)$_GET['article'];
    
$query        mysqli_query($dbc"SELECT * 
                                      FROM "
TABLE 
                                     
" ORDER BY id DESC
                                         LIMIT 1"
);
    
$article     = array();
    while (
$a mysqli_fetch_array($query)) {
        
$article['id']             = $a['id'];
        
$article['date']         = $a['date'];
        
$article['location']     = $a['location'];
        
$article['title']         = $a['title'];
        
$article['summary']     = $a['summary'];
        
$article['article']     = $a['article'];
    }
}else {
    
    
$article     = (int)$_GET['article'];
    
$query        mysqli_query($dbc"SELECT * 
                                      FROM "
TABLE 
                                     
" WHERE id = $article");
    
$article     = array();
    while (
$a mysqli_fetch_array($query)) {
        
$article['id']             = $a['id'];
        
$article['date']         = $a['date'];
        
$article['location']     = $a['location'];
        
$article['title']         = $a['title'];
        
$article['summary']     = $a['summary'];
        
$article['article']     = $a['article'];
    }
}                         
    
    
$smarty->assign('article'$article);            
                
$smarty->assign('news'$result); 

$smarty->display('newsroom.tpl');

?>
I want to take code like this and convert it in to class(es). How do I look at this and say hey this should be a class ? I'm so lost on the simple stuff in OOP that I cannot move on. No matter how much I read and attempt I feel it's wrong. That and I just cannot wrap my head around the idea of taking something like a similiar mysql query and throw it in to a class.

Also .. if anyone has any suggestions on how to better my code please let me know :D
xperience 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


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

 
     

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