Hallo zusammen,
ich habe mal wieder ein Problem wo ich gerade nicht mehr durchsteige. Die Funktion „Create_Page_Data“ gibt mir leider die gewünschten Werte nicht aus. Komme auch nicht dahinter. Ist auch mein erster Versuch im Bereich Klassen und Funktionen, deswegen wäre ich über jeden Performance-, Sicherheits- oder sonstigen Tipp sehr dankbar.
Hier mal die Datei in der die Funktion liegt:
Und so wird das ganze aufgerufen:
Die Funktion
Hoffe wir kommen da weiter. Danke,
Daniel
ich habe mal wieder ein Problem wo ich gerade nicht mehr durchsteige. Die Funktion „Create_Page_Data“ gibt mir leider die gewünschten Werte nicht aus. Komme auch nicht dahinter. Ist auch mein erster Versuch im Bereich Klassen und Funktionen, deswegen wäre ich über jeden Performance-, Sicherheits- oder sonstigen Tipp sehr dankbar.
Hier mal die Datei in der die Funktion liegt:
PHP:
<?php
class db_com {
protected $dbhost = "xxxxxx";
protected $dbuser = "xxxxxx";
protected $dbpass = "xxxxxx";
protected $dbname = "xxxxxx";
protected $db_status = "disconnected";
protected $connection_id;
protected $errormessage;
protected $errornumber;
protected $id = 0;
// Variablen aus Page_Data Select
protected $Page_Path;
protected $Hersteller;
protected $Hauptkategorie;
protected $Subkategorie;
protected $Kategorie01;
protected $Kategorie02;
// Variablen aus Create_Page_Data Select
protected $cp_PagePath;
protected $cp_ImagePat;
protected $cp_Hersteller;
protected $cp_Modellbezeichnung;
protected $cp_Hauptkategorie;
protected $cp_Subkategorie;
protected $cp_Kategorie01;
protected $cp_Kategorie02;
protected $cp_Finanzierung;
protected $cp_Neu;
protected $cp_Produkt_Beschreibung;
// Protect für sonstige Variablen
protected $page_data_select;
protected $query_page_data;
protected $query_result_page_data;
protected $create_page_select;
protected $query_create_page;
protected $query_result_create_page_data;
// ----------------------------------------------------Verbindung zum DB Server herstellen----------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------
public function Establish_Connection() {
if($this->db_status == "disconnected") {
$this->connection_id = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass);
$this->errormessage = mysql_error();
$this->errornumber = mysql_errno();
return $this->db_status = "connnected";
}else{
echo "Fehler in function: Establish_Connection";
return $this->db_status = "disconnected";
}
}
// ----------------------------------------------------Mit Datenbank Verbinden----------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------
public function Select_DB() {
if($this->db_status != "disconnected") {
$this->selected_db = mysql_select_db($this->dbname, $this->connection_id);
$this->errormessage = mysql_error();
$this->errornumber = mysql_errno();
}else{
echo "Fehler in function: Select_DB";
return $this->db_status = "disconnected";
}
}
// ----------------------------------------------------Seiten ID holen-----------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------
public function Get_ID() {
$this->id = mysql_real_escape_string($_GET['id']);
if($this->id == '') {
echo "<h1 style=\"color:#F00;\">Hack attempt!!</h1>";
}else{
return $this->id;
}
}
// ----------------------------------------------------Page Data Select----------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------
public function Page_Data() {
$this->page_data_select = " SELECT PagePath, Section, Hersteller, Hauptkategorie, Subkategorie, Kategorie01, Kategorie02
FROM link_verwaltung
WHERE LinkID = ".$this->id."";
if($this->db_status != "disconnected") {
$this->query_page_data = mysql_query($this->page_data_select, $this->connection_id);
if($this->query_result_page_data = mysql_fetch_array($this->query_page_data)) {
mysql_free_result($this->query_page_data);
}
$this->Page_Path = $this->query_result_page_data['PagePath'];
$this->Section = $this->query_result_page_data['Section'];
$this->Hersteller = $this->query_result_page_data['Hersteller'];
$this->Hauptkategorie = $this->query_result_page_data['Hauptkategorie'];
$this->Subkategorie = $this->query_result_page_data['Subkategorie'];
$this->Kategorie01 = $this->query_result_page_data['Kategorie01'];
$this->Kategorie02 = $this->query_result_page_data['Kategorie02'];
$this->errormessage = mysql_error();
$this->errornumber = mysql_errno();
}else{
echo "Fehler in function: Page_Data<br>\n";
return $this->db_status = "disconnected";
}
}
// ----------------------------------------------------Interpretiert den Query---------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------
public function Interpret_Query() {
if($this->Page_Path != '') {
return (include $this->Page_Path);
}else{
$this->Choose_Create_Page_Function();
}
}
// ----------------------------------------------------Funktion wählt aus, welche Funktion zum Seite erstellen benutzt wird------------------------------------------
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------
protected function Choose_Create_Page_Function() {
if(!($this->Subkategorie == '')) {
echo "Call Create_Producer_Index<br>\n";
$this->Create_Producer_Index();
}else{
$this->Create_Page_Data();
}
}
// ----------------------------------------------------Create Page Select--------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------
protected function Create_Page_Data() {
$this->create_page_select = " SELECT PagePath, ImagePath, Hersteller, Modellbezeichnung, Hauptkategorie, Subkategorie, Kategorie01, Kategorie02, Aktiv, Finanzierung, Neu, Produkt_Beschreibung
FROM produkte
WHERE Hersteller = '".$this->Hersteller."'
AND Hauptkategorie = '".$this->Hauptkategorie."'
AND Subkategorie = '".$this->Subkategorie."'
AND Kategorie01 = '".$this->Kategorie01."'
AND Kategorie01 = '".$this->Kategorie02."'
AND Aktiv = 1";
$this->query_create_page = mysql_query($this->create_page_select, $this->connection_id);
$this->query_result_create_page_data = mysql_fetch_array($this->query_create_page, MYSQL_ASSOC));
$this->mysql_free_result($this->query_result_create_page_data);
}
// ----------------------------------------------------Funktion erstellt Hersteller Index Seite----------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------
public function Create_Producer_Index() {
echo "Herstellerindex bauen<br>\n";
}
// ----------------------------------------------------Funktion erstellt Produkt Index Seite-------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------
protected function Create_Product_Index() {
echo "\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"artikel_table\">";
printf ("<tr>
<td class=\"left\"><img src=\"". $this->query_result_create_page_data['ImagePath'] ."\" alt=\"". $this->query_result_create_page_data['Hersteller'] ." ". $this->query_result_create_page_data['Modellbezeichnung'] ." \"></td>
<td><strong>". $this->query_result_create_page_data["Hersteller"] ." ". $this->query_result_create_page_data["Modellbezeichnung"] ."</strong><br>
". $this->query_result_create_page_data['Produkt_Beschreibung'] ."<br>
<a href=\"". $this->query_result_create_page_data['PagePath'] ."\" class=\"readmore\" alt=\"Lesen Sie weiter...\">Lesen Sie mehr...</a></td>
</tr>"
,$this->query_result_create_page_data['PagePath'], $this->query_result_create_page_data['ImagePath'], $this->query_result_create_page_data['Hersteller'], $this->query_result_create_page_data['Modellbezeichnung'], $this->query_result_create_page_data['Produkt_Beschreibung']
);
print "</table>";
}
// ----------------------------------------------------Letzten Fehler ausgeben----------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------
protected function free_query() {
mysql_free_result();
}
// ----------------------------------------------------Letzten Fehler ausgeben----------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------
public function Get_last_error() {
if($this->db_status == "disconnected") {
return (print "Fehlernummer: ".$this->errornumber . "<br>\n Fehlerbeschreibung: " . $this->errormessage);
}
}
// ----------------------------------------------------Script Ende----------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------
}
Und so wird das ganze aufgerufen:
PHP:
require_once 'scripte/functions/db_com.php';
$db_com = new db_com();
$db_com->Establish_Connection();
$db_com->Select_DB();
$db_com->Get_ID();
$db_com->Page_Data();
$db_com->Interpret_Query();
$db_com->get_last_error();
Die Funktion
Hoffe wir kommen da weiter. Danke,
Daniel
Zuletzt bearbeitet: