*コードアップ用一時領域 [#m31127cf] -インデント,ハイライト,行数表示ができます。 **ソースコードのアップの仕方 [#g391ba3e] このページの上のメニューから[編集]ボタンを押し、 #code(言語名)<<CODE_EOF (この部分にソースコードを貼り付け) CODE_EOF を内容の末尾に追加してください。(#code,CODE_EOFの行頭にはスペースを空けないでください) 書けたら、[ページの更新]ボタンを押します。 **コード [#fc4dcee8] /////------------ここから下に書きます -------------------------- #code(PHP)<<CODE_EOF bbs.phpです /*掲示板本編*/ <?php require_once("Init_class.php"); $init_obj=new Init_class(); $in_disp_from=$_GET["in_disp_from"]; if(!$in_disp_from=intval($in_disp_from)){ $in_disp_from=0; } $in_disp_to=$in_disp_from+100; $in_limit=$_GET["in_limit"]; $in_limit=intval($in_limit); /*テーブル名未決定*/ $sql="select count(*) from bbs_table"; $count_result=$init_obj->db_object->getOne($sql); /*以下検討の必要あり*/ $sql="select message_sequence,contributor,mail_addres,message,write_date" ."from bbs_table order by message_sequence desc" ."limit".$in_disp_from.",".$in_limit; $db_result=$init_obj->db_object->query($sql); disp_html_header($init_obj->bbs_name); ?> <?php disp_link($in_disp_from,$in_disp_to,100,$count_result,"bbs.php",100); disp_all_link(0,"bbs.php",1000); disp_new_link( ?> <hr/> /*タイトルの色を変更する必要あり*/ <left> <?php print($init_obj->bbs_name); ?> </left> /*前後リンク(完)、全部(完)、最新も必要&while文により文の表示*/ <?php disp_link($in_disp_from,$in_disp_to,100,$count_result,"bbs.php",100); disp_all_link(0,"bbs.php",1000); while($value=$db_result->fetchRow(DB_FETCHMODE_ASSOC)){ disp_write_list($value); } ?> <hr/> /*投稿欄*/ <p><input type="submit" value="書き込む" name="submit"> 名前:<input type="text" name="in_contributor" size="15" maxlength="20" value="<?php print($_COOKIE["c_contributor"]) ?>" > E-mail(省略可):<input type="text" name="in_mail" size="15" maxlength="30" value="<?php print($_COOKIE["c_mail"]) ?>" ></p> <p><textarea name="in_message" rows="5" cols="70" wrap="off"></textarea> <?php disp_html_footer(); $init_obj->db_object->disconnect(); ?> html_disp.phpです <?php /*ヘッダの設定*/ function disp_html_header($p_title){ $html_string="<html>\n<head>\n<title>".$p_title."</title>\n"."<meta http-equiv=\"Content-Type\" content=\text/html;charset=EUC-JP\">\n" ."<style type=\"text/css\">\n" /*<!---->はコメント*/ ."<!--\n" ."body{font-size:10pt;font-weight:normal;color:#000000;background:lightgray;}\n" ."td{font-size:10pt;font-weight:normal;color:#000000;background:lightgray;}\n" ."th{font-size:10pt;font-weight:normal;color:#000000;background:lightgray;}\n" ."title{font-size:13pt;font-weight:normal;color:#FF0000;background:lightgray;}\n" ."-->\n" ."</style>" ."</head><body>\n"; print(html_string); } /*フッタの設定*/ function disp_html_footer(){ $html_string="</body></html>"; print($html_string); } /*前後へのリンク表示*/ function disp_link($p_from,$p_to,$p_max,$p_count,$p_link,$p_limit){ if($p_from!=0){ $before_num=$pfrom-$p_max; if(before_num<0){ $begfore_num=0; } $move_link="<a href=\"".$p_link."?in_disp_from=".$before_num."&in_limit=".$p_limit."\">前の".$p_max."件</a>"; /*<a href="$plink?in_disp_from=$before_num&in_limit=100">前の$p_max件</a>*/ } if($p_to<$p_count){ $after_num=$p_from+$p_max; $move_link=$move_link."<a href=\"".$p_link."?in_disp_from=".after_num."&in_limit=".$p_limit."\">次の".$p_max."件</a>"; /*<a href="$p_link?in_disp_from=$after_num&in_limit=100">次の$p_max件</a>*/ } print($move_link); } /*全表示へのリンク*/ function disp_all_link($p_from,$p_link,$p_limit){ $move_all_link="<a href\"".$p_link."?in_disp_from=".$p_from."&in_limit=".$p_limit."\">全部</a>"; print($move_all_link); } /*最新50件を表示*/ function disp_new_link($p_from,$p_to,$p_max,$p_link,$p_limit){ $sql="SELECT COUNT(*)FROM bbs_table"; $new_count_result=$init_obj->db_object->getOne($sql); /*表示するデータ番号*/ function disp_data_num($p_from,$p_to,$p_count){ $disp_num_from=1+$p_from; if($p_count>=$p_to){ $disp_num_to=$p_to; }else{ $disp_num_to=$p_count; } if($disp_num==0){ $disp_num="投稿されていません"; }else{ $disp_num=$disp_num_from."件目〜".disp_num_to."件目を表示"; } print($disp_num); } /*戻るリンクへの表示*/ function disp_back_link($p_link,$p_name){ $html_string="<a href=\"".$p_link."\">".$p_name."へ戻る</a>"; print($html_string); } /*num:名前:日にする必要あり*/ function disp_write_list($p_value){ print($p_value["message_sequence"].":"); if(strlen($p_value["contributor"])==0){ $p_value["contributor"]="名無し".":"; } if(strlen($p_value["mail_address"])==0){ print($p_value["contributor"].":"); }else{ print("<a href=\"mailto:".$p_value[mail_address]."\">".$p_value["contributor"].":"."</a>"); } ?> [<?php print(gmdate("Y/m/d H:i:s",$p_value["write_date"]+9*3600))?>] <br/> <?php print($p_value["message"])?> <?php } /*文字変換*/ function html_convert($p_string){ $p_string = str_replace("&","&",$p_string); $p_string = str_replace("\"",""",$p_string); $p_string = str_replace("<","<",$p_string); $p_string = str_replace(">",">",$p_string); $p_string = str_replace(",",",",$p_string); $p_string = str_replace("'","'",$p_string); $p_string = str_replace("\r\n","\n",$p_string); $p_string = str_replace("\r","\n",$p_string); $p_string = str_replace(" "," ",$p_string); $p_string = str_replace("\n","<br />",$p_string); return $p_string; } function X_to_Z($p_X,$p_Y,$p_Z,$p_N = ""){ if($p_X == $p_Y){ $return_string = $p_Z; }else{ if($p_N != ""){ $return_string = $p_N; }else{ $return_string = $p_X; } } return $return_string; } ?> Init_class.phpです <?php require_once("DB.php"); require_once("html_disp.php"); class Init_class{ var $db_object; /*decodekeyとは?*/ var $decode_key="abcdefg"; var $db_user="usr"; var $db_pass="passwd"; /*以下変更の必要あり*/ var $db_host="localhost"; var $db_name="kisop"; var $bbs_name="キソピー掲示板"; /*以下function群*/ /*コンストラクタによりデータベースに接続 データベースサーバの接続://ユーザ名:パスワード@ホスト名/データベース名*/ function Init_class(){ $db_string="mysql://".$this->db_user.":".$this->db_pass."@".$this->db_host."/".$this->db_name; $this->db_object=DB::connect($db_string); } /*本文文字数過多のためのエラーメッセージ*/ function max_length_check($p_string,$p_length,$p_name){ if(strlen($p_string)>$p_length){ $this->disp_err_message($p_name."が長すぎます(最大半角".p_length."文字)"); } } /*本文文字数過少のためのエラーメッセージ*/ function min_length_check($p_string,$p_length,$p_name){ if(strlen($p_string<$p_length)){ $this->disp_err_message($p_name."が短すぎます(最低半角".p_length."文字)"); } } /*必須入力のためのエラーメッセージ*/ function indi_check($p_string,$p_name){ if(strlen($p_string)==0){ $this->disp_err_message($p_name."は必ず入力してください"); } } /*メールアドレス入力の際のエラーメッセージ*/ function mail_check($p_string){ if(strlen($p_string)!=0&&!ereg("^[a-zA-Z0-9_\.\-]+@(([a-zA-Z0-9_\-]+\.)+[a-zA-Z0-9]+$)",$p_string)){ $this->disp_err_message("メールアドレスを正しく入力してください"); } } /*エラーメッセージのためのfunction*/ function disp_err_message($p_message){ disp_html_header("エラー"); $html_string="<div class=\"title\">".$p_message."</div><hr/><br/><a href=\"#\" onClick=\"history.back(); return false;\">前へ戻る</a>"; print($html_string); $this->db_object->dissconect(); disp_html_footer(); exit; } /*暗号キーを返す*/ function get_decode_key(){ return $this->decode_key; } } ?> CODE_EOF