我有一個PHP類,擴展了另一個類,但我只得到MySQL在擴展類而不是第一類工作。任何人都知道問題是什麼?我似乎無法在所有現在弄明白:SPHP類,擴展數據庫不工作
# Vote class.
class vote {
public $newsID;
private $db;
# Construct.
public function __construct() {
global $_database;
$this->db = $_database;
}
# Vote Up.
public function voteUp() {
return '<a href="#" class="fa fa-angle-up" style="position:absolute;top: 1px; right: 10px;"></a>';
}
public function voteScore($newsID) {
$vote = mysqli_fetch_object($this->db->query("SELECT * FROM ".PREFIX."news WHERE newsID='".$newsID."' LIMIT 1"))->vote;
return '<span class="BigFontSize" style="position:absolute; top: 37px;right: 14px;">'.$vote.'</span>';
}
public function voteDown() {
return '<a href="#" class="fa fa-angle-down" style="position:absolute; bottom: 0;right: 10px;"></a>';
}
}
# News class.
class news extends vote {
public $countNews;
private $db;
# Construct.
public function __construct() {
global $_database;
$this->db = $_database;
}
# Count News.
public function countNews() {
return $this->db->query("SELECT * FROM ".PREFIX."news ORDER BY date DESC")->num_rows;
}
# Print the news.
public function GetNews() {
$newsArray = array();
$sql = $this->db->query("SELECT * FROM ".PREFIX."news ORDER BY date DESC");
while ($rad = $sql->fetch_array()) {
$newsArray[] = array('headline' => $rad['headline'], 'content' => $rad['content'], 'date' => $rad['date'], 'poster' => $rad['userID'], 'published' => $rad['published'], 'intern' => $rad['intern'], 'newsID' => $rad['newsID']);
}
return $newsArray;
}
}
這是票類,可是沒有運作數據庫。我錯過了什麼嗎?
你得到的錯誤是什麼? –
備註:儘管有人可能會開始在twitter和reddit的世界中這樣想,但一個新聞不是投票。新聞文章可能是關於投票,或者可能是與新聞相關的投票/投票,但是「新聞延伸投票」......這聽起來不對。 – VolkerK
向我們展示了你實例化你的'news'對象並且有任何問題或錯誤信息的代碼片段? – Alex