05-16-2008, 02:39 AM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Dec 2007
Posts: 18
Thanks: 2
|
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(HOST, USERNAME, PASSWORD, DATABASE);
/* 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
|
|
|
|