ようこそ! このブログは、PHPとMysqlを使って作成したオリジナルプログラムを、QHMに読み込んで表示させています。

Comment.class.php

FrontPage

Comment.class.phpのソースコード

<?php

require_once "BaseDB.class.php";
// ログインをするクラス
class Comment extends BaseDB
{
	public function loadComment( $comid='' )
	{
		$qstring = "select  comid,topicid,dt,ipaddr,hostname,comname,mailaddr," .
				"title,body from b_comments  where comid=$comid";
		//クエリを実行
		$qresult = mysql_query($qstring);
		if(!$qresult){
			$this->errorm = "DB Error:[$qstring]";
			$this->errors++;
			return false;
		}
		if(!$fresult = mysql_fetch_array($qresult))
		{
			$this->errorm = "コメント情報がありません。";
			$this->errors++;
			return false;
		}
		
		$this->comid = $fresult['comid'];
		$this->topicid = $fresult['topicid'];
		$this->dt = $fresult['dt'];
		$this->ipaddr = $fresult['ipaddr'];
		$this->hostname = $fresult['hostname'];
		$this->comname = $fresult['comname'];
		$this->mailaddr = $fresult['mailaddr'];
		$this->title = $fresult['title'];
		$this->body = $fresult['body'];
		
		return true;
	}

	public function saveComment()
	{
		if( $this->comid == 0 ){
			$qstring = "insert into b_comments (topicid,dt,ipaddr,hostname,comname,mailaddr,title,body)values(" .
				"$this->topicid,NOW(),'$this->ipaddr','$this->hostname','$this->comname','$this->mailaddr','$this->title','$this->body')";
		} else {
			$qstring = "update b_comments set ".
				"comname = '$this->comname', ".
				"mailaddr = '$this->mailaddr', ".
				"title = '$this->title', ".
				"body = '$this->body' ".
				" where comid='$this->comid'";
		}
		//クエリを実行
		$qresult = mysql_query($qstring);
		if(!$qresult){
			$this->errorm = "DB Error:[$qstring]";
			$this->errors++;
			return false;
		}
		
		return true;
	}

	public function getComments($topicid=0)
	{
		if( $topicid == 0 ){
		$qstring = "select comid,topicid,DATE_FORMAT( dt,'%Y/%m/%d %T') as postdatef," .
			  	"comname,mailaddr,title,body " . 
				" from b_comments order by comid";
		} else {
		$qstring = "select comid,topicid,DATE_FORMAT( dt,'%Y/%m/%d %T') as postdatef," .
			 	"comname,mailaddr,title,body " . 
				" from b_comments where topicid=$topicid order by comid";
		}
		//クエリを実行
		$qresult = mysql_query($qstring);
		if(!$qresult){
			$this->errorm = "DB Error:[$qstring]";
			$this->errors++;
			echo $this->errorm ;
			return false;
		}
		$all = array();
		while( $rec = mysql_fetch_assoc($qresult) ){
			$rec['bodyf'] = ereg_replace( "\n","<br>", $rec['body'] );
			$rec['bodyf'] = ereg_replace( "<br><br>","</p>\n<p>", $rec['bodyf'] );
			$rec['bodyf'] = '<p>' . $rec['bodyf'] . '</p>';
			
			$all[] = $rec;
		}
		return $all;
	}

	public function deleteComment( $id )
	{
		$qstring = "delete from b_comments where comid = $id";
		//クエリを実行
		$qresult = mysql_query($qstring);
		if(!$qresult){
			$this->errorm = "DB Error:[$qstring]";
			$this->errors++;
			return false;
		}
		
		return true;
	}

	// プロパティ参照
	function __get( $property )
	{
		return $this->$property;
	}
	// プロパティセット
	function __set( $property, $value )
	{
		$this->$property = $value;
	}
} //クラス終了


?>

powered by Quick Homepage Maker 4.25
based on PukiWiki 1.4.7 License is GPL. QHM

最新の更新 RSS  Valid XHTML 1.0 Transitional