我创建了一个名为PriviewMode的类
class PriviewModel {
private $TOPIC_ID = array();
private $SECTION_ID = array();
private $ADDITION_TEXT_SEQ = array();
private $TOPIC_HYPERLINK = array();
private $TOPIC_NAME = array();
private $TOPIC_TEXT = array();
private $CATEGORY_ID = array();
private $CONTRIBUTED_BY = array();
private $APPROVED_FOR_LIVE = array();
private $LAST_UPDATED = array();
function getTOPIC_ID() {
return $this->TOPIC_ID;
}
function getSECTION_ID() {
return $this->SECTION_ID;
}
function getADDITION_TEXT_SEQ() {
return $this->ADDITION_TEXT_SEQ;
}
function getTOPIC_HYPERLINK() {
return $this->TOPIC_HYPERLINK;
}
function getTOPIC_NAME() {
return $this->TOPIC_NAME;
}
function getTOPIC_TEXT() {
return $this->TOPIC_TEXT;
}
function getCATEGORY_ID() {
return $this->CATEGORY_ID;
}
function getCONTRIBUTED_BY() {
return $this->CONTRIBUTED_BY;
}
function getAPPROVED_FOR_LIVE() {
return $this->APPROVED_FOR_LIVE;
}
function getLAST_UPDATED() {
return $this->LAST_UPDATED;
}
function setTOPIC_ID($TOPIC_ID) {
$this->TOPIC_ID = $TOPIC_ID;
}
function setSECTION_ID($SECTION_ID) {
$this->SECTION_ID = $SECTION_ID;
}
function setADDITION_TEXT_SEQ($ADDITION_TEXT_SEQ) {
$this->ADDITION_TEXT_SEQ = $ADDITION_TEXT_SEQ;
}
function setTOPIC_HYPERLINK($TOPIC_HYPERLINK) {
$this->TOPIC_HYPERLINK = $TOPIC_HYPERLINK;
}
function setTOPIC_NAME($TOPIC_NAME) {
$this->TOPIC_NAME = $TOPIC_NAME;
}
function setTOPIC_TEXT($TOPIC_TEXT) {
$this->TOPIC_TEXT = $TOPIC_TEXT;
}
function setCATEGORY_ID($CATEGORY_ID) {
$this->CATEGORY_ID = $CATEGORY_ID;
}
function setCONTRIBUTED_BY($CONTRIBUTED_BY) {
$this->CONTRIBUTED_BY = $CONTRIBUTED_BY;
}
function setAPPROVED_FOR_LIVE($APPROVED_FOR_LIVE) {
$this->APPROVED_FOR_LIVE = $APPROVED_FOR_LIVE;
}
function setLAST_UPDATED($LAST_UPDATED) {
$this->LAST_UPDATED = $LAST_UPDATED;
}
为它创建一些getter和setter方法。变量是数组。现在的问题是如何在这个类varibles中设置mysql_fetch_object的结果集。喜欢
foreach($results as $result){
$privewmodel->setTOPIC_ID($result->topic_id);
.....
}
答案 0 :(得分:1)
如果我理解你的问题,我认为这就是你需要的:
$previousValue = $privewmodel->getTOPIC_ID();
$newValue = array_merge($previousValue, $result->topic_id);
$privewmodel->setTOPIC_ID($newValue);
基本上获取当前数组,并使用array_merge()
将新值附加到其中。