See below below
I'm trying to dive into OOP development in PHP, and I'm really starting to breed a headache or ulcer. I just can’t wrap my head around, the parts seem too illogical to me, and I don’t know where to start, and it really upsets me, because I consider that it is worth trying to study it, and it gives me a better overview about my code.
Yesterday I spent the whole day looking for practical examples and explanatory articles on the Internet, but now I have the feeling that it only bothers me. I need some practical advice, not examples like
class person {
var $name;
function set_name($new_name) {
$this->name = $new_name;
}
function get_name() {
return $this->name;
}
}
$stefan = new person();
$jimmy = new person;
$stefan->set_name("Stefan");
$jimmy->set_name("Jimmy");
echo "Stefan full name: " . $stefan->get_name();
echo "Jimmy full name: " . $jimmy->get_name();
Examples like this make me wonder why I shouldn't (because it's all defined on the same page) just
$name = "Stefan";
echo "Stefan full name: ".$name;
Shorter (less code) and more obvious if you ask me?
Nou .
, , - - . 4 , , , . clients, content media, .
( , , ) -
class Database{}
class Content extends Database{}
function showMenu(){}
function showContent{}
class Clients extends Database{}
function showClientList{}
function showClientDetails{}
class Media extends Database{}
, query($qry). content :
class Content extends Database {
public function topMenu($page){
$db = new Database();
$db->connect();
$db->query("SELECT m_link, m_title, m_accesskey FROM menu WHERE m_type = 'top'");
$res = $db->getResult();
foreach($res AS $show){
if($page == $show['m_link']){
echo("<li id="active">$show['m_title']."</li>\n");
}else{
echo("<li>$show['m_title']."</li>\n");
}
}
}
}
?
index.php ( ) $content = new Content(); $content->topMenu($_aGET[0]);
, , - , $_aGET[0] ( URL)
, , , , ,
$query = "
SELECT cl.c_id, cl.c_client, cl.c_client_desc, ncc.clco_cl_id, ncc.clco_co_id, co.c_content, ncm.clme_me_id, ncm.clme_cl_id, GROUP_CONCAT(me.m_link) AS images_link
FROM clienten AS cl
LEFT JOIN norm_cl_co_rel AS ncc ON cl.c_id = ncc.clco_cl_id
LEFT JOIN content AS co ON ncc.clco_co_id = co.c_id
LEFT JOIN norm_cl_me_rel AS ncm ON cl.c_id = ncm.clme_cl_id
LEFT JOIN media AS me ON me.m_id = ncm.clme_me_id
WHERE cl.c_client = '".mysql_real_escape_string($_aGET[1])."'
AND cl.c_language_id = '"._LANGUAGE."'
AND cl.c_active = '1'
";
, , (?) ?
"" : ", "
EDIT:
, Fluffeh , . , , .
ID: CompanyName
C
Desc: C
Media:
:
:
:
:
:
( ):
ID: CompanyName
CompanyName
Desc: CompanyName is a company
Media:
: Image 1
: Image 2
: Image 3
: Image 4
: Image 5
:
class media{
public $type;
public $title;
public $image;
public $desc;
}
class client{
public $name;
public $desc;
}
class clientDetails{
private $clientID;
public $clientName;
public $clientDesc;
public $clientMedia = array();
public $clientMediaFiles = 0;
public function __construct($myID){
$this->clientID = $myID;
}
public function getMyDetails(){
$db = new Database();
$db->connect();
$db->query("
SELECT c_client, c_client_desc
FROM clienten
WHERE c_client = '".mysql_real_escape_string($this->clientID)."'
");
foreach($db->getResult() as $client){
$this->name = $client['c_client'];
$this->desc = $client['c_client_desc'];
}
$db = new Database();
$db->connect();
$db->query("
SELECT ncm.clme_me_id, ncm.clme_cl_id, cl.c_id, me.m_id, me.m_type, me.m_title, me.m_desc, me.m_link
FROM norm_cl_me_rel AS ncm
LEFT JOIN clienten AS cl ON cl.c_id = ncm.clme_cl_id
LEFT JOIN media AS me ON me.m_id = ncm.clme_me_id
WHERE me.m_id IN(1,2,3,4,5)
");
foreach($db->getResult() as $media){
$this->clientMedia[$i]= new media();
$this->clientMedia[$i]->type = $media['m_type'];
$this->clientMedia[$i]->title = $media['m_title'];
$this->clientMedia[$i]->image = $media['m_image'];
$this->clientMedia[$i]->desc = $media['m_desc'];
$this->clientMediaFiles++;
}
}
public function displayMyResults(){
echo "ID: $this->clientID";
echo "<div><h3>".$this->name."</h3>";
echo "Desc: ".$this->desc."<br>";
echo "Media:<br>";
for($i=0;$i<$this->clientMediaFiles;$i++){
echo $this->clientMedia[$i]->title." : ".$this->clientMedia[$i]->desc."<br>";
}
echo "</div>";
}
}