added session to database
authorarun <arun@nubati.net>
Sat, 3 Feb 2007 04:57:04 +0000 (04:57 +0000)
committerarun <arun>
Sat, 3 Feb 2007 04:57:04 +0000 (04:57 +0000)
create_database.sql
db.php
index.php

index 88c41d9d41fe81498e76132a2b94d892363cb630..bec23256dcb1a218ce87e5a5300afcbcd541927d 100644 (file)
@@ -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 1b047d39ce104735bfe40658566928d5f5131d15..38b788cd70d6c41bce8aa6d013b55be06e555ca9 100644 (file)
--- 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
index cbcc2f2f0d699a5c460ea41650065e0b7db621c3..e58bae69b437e6bb81b01607e4c4dbe28d8d8bb3 100644 (file)
--- 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)");