summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarun <arun@nubati.net>2007-02-03 04:57:04 +0000
committerarun <arun>2007-02-03 04:57:04 +0000
commit15e85c12f9392246845f5c611f5faafe8660a9e2 (patch)
treecd3d9c99427ce11b60ba2d3ae2acf24a3a85b455
parent0ef11ea847d9891e19605e6c93cb4c7296df0a57 (diff)
downloade-DoKo-15e85c12f9392246845f5c611f5faafe8660a9e2.tar.gz
e-DoKo-15e85c12f9392246845f5c611f5faafe8660a9e2.tar.bz2
e-DoKo-15e85c12f9392246845f5c611f5faafe8660a9e2.zip
added session to database
-rw-r--r--create_database.sql2
-rw-r--r--db.php23
-rw-r--r--index.php12
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)");