0

Hello! I've been stuck with this for a while now. First I want to say that this is a school project and not something illegal bet site.

The first MySQL table have results from games and the other table contains users bets on different games..
My problem is that I don't know how to make the two tables compare and then by that change some numbers in MySQL table.

So I want the code to look if the team1 and team2 on both tables are the same. Then look if the bets (1,X or 2) are the same. If they are, change (in table "Bets") w to 1 and if not, change (in table "Bets") l to 1.

I think my problem might be that i don't know how to make the while loop...

This is my code:

$tbl_name="Bets";

$tbl_name2="results";

//connect to MySQL and chose database
mysql_connect("$host", "$username", "$password")or die("Connection could not be Established");
mysql_select_db("$db_name")or die("Could not select DB");

$loginusername=$_SESSION['loginusername'];

$sql="SELECT * FROM $tbl_name WHERE user='$loginusername'";
$r=mysql_query($sql);
$i=0;
$betarray=array(array());
while($rows=mysql_fetch_array($r))
{
   $betarray[$i]=$rows;
   $i++;
}



foreach($betarray as $insidearray)
foreach($betarray2 as $insidearray1)
{
      while($rows=mysql_fetch_array($r))
      {
         $team1 = $insidearray['team1'];
         $team2 = $insidearray['team2'];      
      if($team1 == $insidearray1['team1'] && $team2 == $insidearray1['team2'])
         {
         $team1 = $insidearray['team1'];
         $team2 = $insidearray['team2'];
         $x12 = $insidearray['1x2real']

            if($x12 == $insidearray1['1x2'])
               {
                  $update="UPDATE $tbl_name SET w='1' WHERE user='$loginusername' AND team1='$team1' AND team2='$team2'";
                  mysql_query($update);
               }
               else
               {
                  $update="UPDATE $tbl_name SET l='1' WHERE user='$loginusername' AND team1='$team1' AND team2='$team2'";
                  mysql_query($update);               
               }

         }


      }
}
}

Thanks in Advance!

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by diafol
0

I haven't understood what you want to do, please find a way of explaining the process a bit better, and also use the CODE tags for PHP code !

Edited by happygeek: fixed formatting

0

Ditto, you need to explain exactly what you're trying to do. Giving your table structure would be a good thing to do as well.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.