Time to move to OOP?
Posted: Wed Jan 09, 2008 10:08 am
Below is a general example of a typical page I would create. Does anyone see it benefiting from an OO approach? This page is called into a template system already. I just want a reason to start learning OOP and need a real example to do so. Any help would be greatly appreciated. (note, there are some consistency issues I'm aware of. I'm rewriting the page)
Code: Select all
<?php
## WORK item
/*************************************************************/
$pid=$_GET['id'];
require_once(DB);
$query="SELECT P.project_id, P.project_name, P.project_des, P.location_id, C.category_full, C.category_id
FROM project P, category C, project_category B
WHERE P.project_id='$pid' AND C.category_id=B.category_id";
$result=mysql_query($query) OR DIE (mysql_error());
list($pid,$pname,$pdes,$plid,$cfull,$cid)=mysql_fetch_array($result);
//Display name and description
if (mysql_num_rows($result)){
echo "<h3>{$pname}</h3>\n";
echo "<p>{$pdes}</p>\n";
//Display project images
$path="images/work/{$pid}/";
$dir=opendir($path);
while($name=readdir($dir)){
if (preg_match("/t+([0-9]+\.jpg)$/",$name,$sp)){
$nameb=ereg_replace('t','', $name);
echo '<a href="'.BASE_URL.$path.$sp[1].'" rel="lightbox" title="'.$pname.'">';
echo '<img class="work" src="'.BASE_URL.$path.$name.'" alt="'.$pname.'" width="130" />';
echo "</a> \r";
}
}
/*************************************************************/
//DEATAILS Section
echo "<p><strong>Details</strong><br />\n";
//Categories the project is listed under
echo "Category: ";
$query="SELECT C.category_full, C.category_id FROM category C, project_category P
WHERE C.category_id=P.category_id
AND
P.project_id='$pid'";
$result=mysql_query($query) OR DIE (mysql_error());
if(!mysql_num_rows($result)){
echo "";
}else{
while(list($cfull,$cid)=mysql_fetch_array($result)){
echo '<a class="workU" href="'.BASE_URL."category-{$cid}.html\">{$cfull}</a>\n";
}
}
echo "<br />\n";
// Locaton of the project
echo "Location: ";
$query="SELECT C.city_name, C.city_id, S.state_abbr, S.state_id
FROM project P, location_city C, location_state S
WHERE P.location_id=C.city_id
AND
C.state_id=S.state_id
AND
P.project_id='$pid'";
$result=mysql_query($query) OR DIE (mysql_error());
if(!mysql_num_rows($result)){
echo "";
}else{
list($city,$cid,$state,$sid)=mysql_fetch_array($result);
$cityd=ereg_replace(' ','-', trim($city));
echo '<a class="workU" href="'.BASE_URL."city-{$cityd}-{$cid}.html\">{$city}</a>, ";
echo '<a class="workU" href="'.BASE_URL."state-{$state}-{$sid}.html\">{$state}</a></p>\n";
}
//PEOPLE
$query="SELECT GROUP_CONCAT(membership_name ORDER BY M.membership_id SEPARATOR ', ') AS membership_name, P.people_id, people_fname, people_mname, people_lname, PR.project_id
FROM membership M,people_membership PM,people P, project PR, people_project PP
WHERE M.membership_id=PM.membership_id
AND
P.people_id=PM.people_id
AND
P.people_id=PP.people_id
AND
PP.project_id=$pid
GROUP BY
P.people_id
ORDER BY P.people_lname ASC";
$result=mysql_query($query) or die (mysql_error());
if(!mysql_num_rows($result)){
echo "";
}else{
echo "<p><strong>People</strong><br />";
while(list($membership,$pid,$fname,$mname,$lname,$prid)=mysql_fetch_array($result)){
echo '<a class="workU" href="'.BASE_URL."bio-{$fname}-{$lname}-{$pid}.html\">{$fname} ";
if($mname) echo "{$mname}. ";
echo "{$lname}</a><br />\n";
}
echo "</p>\n";
}
}else{
echo 'There are no additional details available.';
}
?>