依頼されたツールを誰 ..
[
2ch
|
▼Menu
]
■コピペモード
□
スレを通常表示
□
オプションモード
□このスレッドのURL
■項目テキスト
106:nobodyさん 05/01/04 00:07:21 -- テーブルこんな感じで create table quiz ( id integer unsigned not null auto_increment, question text not null, answer enum('A', 'B', 'C', 'D'), A varchar(64) not null, B varchar(64) not null, C varchar(64) not null, primary key (id) ); 107:nobodyさん 05/01/04 00:07:49 データベース周りの操作をまとめたクラス quiz.php.inc <?php class Quiz { var $table='quiz'; function Quiz() {} function connectDB($dbserver, $username, $password, $database) { @mysql_connect($dbserver, $username, $password); @mysql_select_db($database); } function query($query_string) { $result = @mysql_query($query_string); if (! $result) { printf("MySQL error(%d): %s\n", @mysql_errno(), @mysql_error()); return NULL; } return @mysql_fetch_object($result); } function getAnswer($id) { return $this->query("SELECT `answer` FROM $this->table WHERE `id`=$id;"); } function getQuestion($id) { return $this->query("SELECT `question`,`A`,`B`,`C`,`D` FROM $this->table WHERE `id`=$id;"); } function addQuestion($question, $answer, $answers) { assert(in_array($answer, array('A', 'B', 'C', 'D'))); assert(4 == count($answers)); list($A, $B, $C, $D) = $answers; $this->query("INSERT INTO `$this->table` VALUES(NULL,`$question`,`$answer`,`$A`,`$B`,`$C`,`$D`);"); } } ?> 続きは、また今度。
次ページ
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
レスジャンプ
mixiチェック!
Twitterに投稿
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch
5387日前に更新/56 KB
担当:undef