From 15e85c12f9392246845f5c611f5faafe8660a9e2 Mon Sep 17 00:00:00 2001 From: arun Date: Sat, 3 Feb 2007 04:57:04 +0000 Subject: added session to database --- create_database.sql | 2 +- db.php | 23 +++++++++++++++++++++++ index.php | 12 +++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/create_database.sql b/create_database.sql index 88c41d9..bec2325 100644 --- a/create_database.sql +++ b/create_database.sql @@ -74,7 +74,7 @@ CREATE TABLE `Game` ( `solo` enum('trumpless','jack','queen','trump','club','spade','heart','silent') default NULL, `startplayer` tinyint(4) default '1', `status` enum('pre','play','gameover') default NULL, - `followup_of` int(11) default NULL, + `session` int(11) default NULL, `id` int(11) NOT NULL auto_increment, UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/db.php b/db.php index 1b047d3..38b788c 100644 --- a/db.php +++ b/db.php @@ -512,4 +512,27 @@ function DB_set_startplayer_by_gameid($id,$p) return; } +function DB_get_session_by_gameid($id) +{ + $result = mysql_query("SELECT session FROM Game WHERE id=".DB_quote_smart($id)); + $r = mysql_fetch_array($result,MYSQL_NUM); + + if($r) + return $r[0]; + else + return NULL; +} + +function DB_get_max_session() +{ + $result = mysql_query("SELECT MAX(session) FROM Game"); + $r = mysql_fetch_array($result,MYSQL_NUM); + + if($r) + return $r[0]; + else + return 0; +} + + ?> \ No newline at end of file diff --git a/index.php b/index.php index cbcc2f2..e58bae6 100644 --- a/index.php +++ b/index.php @@ -63,7 +63,17 @@ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD" )) if(myisset("followup") ) { $followup= $_REQUEST["followup"]; - mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre','$followup' ,NULL)"); + $session = DB_get_session_by_gameid($followup); + if($session) + mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre','$session' ,NULL)"); + else + { + /* get max session */ + $max = DB_get_max_session(); + $max++; + mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre','$max' ,NULL)"); + mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup)); + } } else mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre', NULL ,NULL)"); -- cgit v1.2.3-18-g5258