BUGFIX: order games by session
authorArun Persaud <arun@nubati.net>
Mon, 30 Jul 2007 02:17:51 +0000 (19:17 -0700)
committerArun Persaud <arun@nubati.net>
Mon, 30 Jul 2007 02:21:30 +0000 (19:21 -0700)
games are now ordered by sessions, also fixed a typo

db.php
index.php

diff --git a/db.php b/db.php
index 867be1685942db70ce2520630d91a1f5cf6f7c00..a6b9c3b8acb1f80a60c9a3933faaf365ee1de792 100644 (file)
--- a/db.php
+++ b/db.php
@@ -907,9 +907,10 @@ function DB_format_gameid($gameid)
   $session = DB_get_session_by_gameid($gameid);
   
   /* get number of game */
   $session = DB_get_session_by_gameid($gameid);
   
   /* get number of game */
-  $result = mysql_query("SELECT COUNT(*),create_date FROM Game WHERE session='$session' ".
-                       " GROUP by session".
-                       " HAVING TIMEDIFF(create_date, (SELECT create_date FROM Game WHERE id='$gameid'))<=0");
+  $result = mysql_query("SELECT COUNT(*),create_date FROM Game".
+                       " WHERE session='$session' ".
+                       " AND TIMEDIFF(create_date, (SELECT create_date FROM Game WHERE id='$gameid'))<=0 ".
+                       " GROUP by session");
   $r = mysql_fetch_array($result,MYSQL_NUM);
   
   return $session.".".$r[0];
   $r = mysql_fetch_array($result,MYSQL_NUM);
   
   return $session.".".$r[0];
index 57145c6d978ff2669a42a2497aba474d288806a6..cfef15bed5573e6741ec2cbff6ec036f264a5a4e 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1721,10 +1721,11 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
               echo "<p>These are your games that haven't started yet:<br />\n";
               $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player from Hand".
                                     " LEFT JOIN Game On Hand.game_id=Game.id".
               echo "<p>These are your games that haven't started yet:<br />\n";
               $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player from Hand".
                                     " LEFT JOIN Game On Hand.game_id=Game.id".
-                                    " WHERE Hand.user_id='$uid' AND Game.status='pre'" );
+                                    " WHERE Hand.user_id='$uid' AND Game.status='pre'".
+                                    " ORDER BY Game.session" );
               while( $r = mysql_fetch_array($result,MYSQL_NUM))
                 {
               while( $r = mysql_fetch_array($result,MYSQL_NUM))
                 {
-                  echo "<a href=\"".$host."?me=".$r[0]."\">game".DB_format_gameid($r[1])." </a>";
+                  echo "<a href=\"".$host."?me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a>";
                   if($r[3]==$uid || $r[3]==NULL)
                     echo "(it's <strong>your</strong> turn)\n";
                   else
                   if($r[3]==$uid || $r[3]==NULL)
                     echo "(it's <strong>your</strong> turn)\n";
                   else
@@ -1744,7 +1745,8 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
               echo "<p>These are the games you are playing in:<br />\n";
               $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player from Hand".
                                     " LEFT JOIN Game On Hand.game_id=Game.id".
               echo "<p>These are the games you are playing in:<br />\n";
               $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player from Hand".
                                     " LEFT JOIN Game On Hand.game_id=Game.id".
-                                    " WHERE Hand.user_id='$uid' AND Game.status='play'" );
+                                    " WHERE Hand.user_id='$uid' AND Game.status='play'".
+                                    " ORDER BY Game.session" );
               while( $r = mysql_fetch_array($result,MYSQL_NUM))
                 {
                   echo "<a href=\"".$host."?me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a>";
               while( $r = mysql_fetch_array($result,MYSQL_NUM))
                 {
                   echo "<a href=\"".$host."?me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a>";
@@ -1769,7 +1771,10 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
               
               echo "<p>And these are your games that are already done:<br />Game: \n";
               $output = array();
               
               echo "<p>And these are your games that are already done:<br />Game: \n";
               $output = array();
-              $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
+              $result = mysql_query("SELECT hash,game_id from Hand".
+                                    " LEFT JOIN Game ON Game.id=Hand.game_id".
+                                    " WHERE user_id='$uid' AND Game.status='gameover'".
+                                    " ORDER BY Game.session,Game.create_date" );
               while( $r = mysql_fetch_array($result,MYSQL_NUM))
                 $output[] = "<a href=\"".$host."?me=".$r[0]."\">".DB_format_gameid($r[1])." </a>";
               echo implode(", ",$output)."</p>\n";
               while( $r = mysql_fetch_array($result,MYSQL_NUM))
                 $output[] = "<a href=\"".$host."?me=".$r[0]."\">".DB_format_gameid($r[1])." </a>";
               echo implode(", ",$output)."</p>\n";