Jump to content

IF's and MySQL Question (Kinda Weird, I think)


Lamez

Recommended Posts

Alright I have a question, when I put to update querys together, only the points update, but if I move the other query, it only updates. Why?

 

Here is the code: This one adds a 1 to the r1 field, but does not update points.

   if ($a1 != ("emp")){
    if ($ck['r1'] = ("0")){
     if ($a1 = ($pick['a1'])){
      $total = $value + $total;
      $rnd1 = $value + $rnd1;
  mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error());
  }
    }
   mysql_query("UPDATE `check1` SET `r1`='1' WHERE `id`='1'");
}

 

This one updates the userpoints, but does not update a 1 into the r1 field

 

   if ($a1 != ("emp")){
    if ($ck['r1'] = ("0")){
     if ($a1 = ($pick['a1'])){
      $total = $value + $total;
      $rnd1 = $value + $rnd1;
  mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error());
           mysql_query("UPDATE `check1` SET `r1`='1' WHERE `id`='1'");
  }
    }
}

 

How do I get them it to update both tables?

try

 

   if ($a1 != ("emp")){
    if ($ck['r1'] = ("0")){
     if ($a1 = ($pick['a1'])){
      $total = $value + $total;
      $rnd1 = $value + $rnd1;
  mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error());
           mysql_query("UPDATE `check1` SET `r1`='1' WHERE `id`='1'")or die(mysql_error());
  }
    }
}

omg, after weeks of frustration, I have finally figured out a solution.

 

if anyone is wondering, here is my full code:

 

<?php
include ("../../../style/include/session.php");
include ("../../../style/include/cons/head_3.php");
if($session->isAdmin()){

$a1 = $_POST['a1'];
$a2 = $_POST['a8'];
$a3 = $_POST['a5'];
$a4 = $_POST['a4'];
$a5 = $_POST['a6'];
$a6 = $_POST['a3'];
$a7 = $_POST['a7'];
$a8 = $_POST['a2'];

$b9 = $_POST['b1'];
$b10 = $_POST['b8'];
$b11 = $_POST['b5'];
$b12 = $_POST['b4'];
$b13 = $_POST['b6'];
$b14 = $_POST['b3'];
$b15 = $_POST['b7'];
$b16 = $_POST['b2'];

$c17 = $_POST['c1'];
$c18 = $_POST['c8'];
$c19 = $_POST['c5'];
$c20 = $_POST['c4'];
$c21 = $_POST['c6'];
$c22 = $_POST['c3'];
$c23 = $_POST['c7'];
$c24 = $_POST['c2'];

$d25 = $_POST['d1'];
$d26 = $_POST['d8'];
$d27 = $_POST['d5'];
$d28 = $_POST['d4'];
$d29 = $_POST['d6'];
$d30 = $_POST['d3'];
$d31 = $_POST['d7'];
$d32 = $_POST['d2'];

$result=mysql_query('SELECT * FROM userpoints');

while($row = mysql_fetch_array($result)){
$user = $row['username']; 
   /*Pull Winners for Round 1*/
  $q = mysql_query("Select * from `rnd1_win`");
  $win=mysql_fetch_array($q);
   
  /*Pull User Picks for Round 1*/
  $q = mysql_query("Select * from `rnd1` where `username` = '$user'");
  $pick=mysql_fetch_array($q);
  
  /*Pull Point Values for Round 1*/
  $q = mysql_query("Select rnd1 from `points`");
  $point=mysql_fetch_array($q);
  $value = $point['rnd1'];
  
  /*Pull User Points for Round 1*/
  $q = mysql_query("Select `username`, `total`, `rnd1` from `userpoints` Where `username` = '$user'");
  $usrpoint=mysql_fetch_array($q);
  $total = $usrpoint['total'];
  $rnd1 = $usrpoint['rnd1'];
     

#A's
  
   if ($a1 !== ("emp")){
    if ($win['1'] == ("emp")){
     if ($a1 == ($pick['a1'])){
        $total = $value + $total;
        $rnd1 = $value + $rnd1;
    mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error());
  }  
}
  }
  
  
}
$q = "UPDATE `rnd1_win` SET `1` = '$a1', `2` = '$a2', `3` = '$a3', `4` = '$a4', `5` = '$a5', `6` = '$a6', `7` = '$a7', `8` = '$a8', `9` = '$b9', `10` = '$b10', `11` = '$b11', `12` = '$b12', `13` = '$b13', `14` = '$b14', `15` = '$b15', `16` = '$b16', `17` = '$c17', `18` = '$c18', `19` = '$c19', `20` = '$c20', `21` = '$c21', `22` = '$c22', `23` = '$c23', `24` = '$c24', `25` = '$d25', `26` = '$d26', `27` = '$d27', `28` = '$d28', `29` = '$d29', `30` = '$d30', `31` = '$d31', `32` = '$d32' WHERE `id` = '1'";
mysql_query($q) or die(mysql_error());

print '<div class="box"><h2>Winners Updated</h2>';
print '<p>Winners Updated for Round 2<br><br>';
print '<a href="slcwin_1.php">Round 2</a></p>';
print '</div>';
}else{
header("Location: ../../../index.php");
}
include ("../../../style/include/cons/foot.php");
?>

 

It works how I want it to :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.