Jump to content

Help with calculating


bancnn

Recommended Posts

I created a website for the world cup result. each user add score of each game and if they get the score right they get 3 points if they get the winner right they get 1 point. I am having a problem calculating. I am using a array to show all the result and from that array i calculate the points. i want to save those result for each player on the database. i try this :

 

while ($row = mysql_fetch_array($result))

{

$f1=$row['firstname'];

$e1=$row['emailname'];

$sA= $_POST['sumA'];

$sB= $_POST['sumB'];

$sC= $_POST['sumC'];

$sD= $_POST['sumD'];

$sE= $_POST['sumE'];

$sF= $_POST['sumF'];

$sG= $_POST['sumG'];

$sH= $_POST['sumH'];

$sumTOTAL = $sA + $sB + $sC + $sD + $sE + $sF + $sG + $sH;

 

?>

 

 

 

<?PHP

mysql_select_db($db_name);

$sql="INSERT INTO score (f1, scoreA, scoreB, scoreC, scoreD, scoreE, scoreF, scoreG, scoreH)

VALUES

('$f1','$sA','$sB','$sC','$sD','$sE','$sF','$sG','$sH')";

?>

 

didn't work.

the website is www.toerrado.com

Link to comment
https://forums.phpfreaks.com/topic/204743-help-with-calculating/
Share on other sites

try executing the SQL query:


while ($row = mysql_fetch_array($result))
   {
   $f1=$row['firstname'];
   $e1=$row['emailname'];
   $sA= $_POST['sumA'];
   $sB= $_POST['sumB'];
   $sC= $_POST['sumC'];
   $sD= $_POST['sumD'];
   $sE= $_POST['sumE'];
   $sF= $_POST['sumF'];
   $sG= $_POST['sumG'];
   $sH= $_POST['sumH'];
   $sumTOTAL = $sA + $sB + $sC + $sD + $sE + $sF + $sG + $sH;

?>



<?PHP
mysql_select_db($db_name);
$sql="INSERT INTO score (f1, scoreA, scoreB, scoreC, scoreD, scoreE, scoreF, scoreG, scoreH)
VALUES
('$f1','$sA','$sB','$sC','$sD','$sE','$sF','$sG','$sH')";
mysql_qmery($sql);
?>

I haven't explain right.

 

This is the code that i am using to display the results that i compare from 2 database:

 

<?php

 

include 'config.php';

$conn = mysql_connect($host, $username, $password) or die             

('Error connecting to mysql');

mysql_select_db($db_name);

$query="SELECT * FROM score";

$result=mysql_query($query);

 

while ($row = mysql_fetch_array($result))

{

$s1=$row[score1];

$s1a=$row[score1a];

$s2=$row[score2];

$s2a=$row[score2a];

$s3=$row[score3];

$s3a=$row[score3a];

$s4=$row[score4];

$s4a=$row[score4a];

$s5=$row[score5];

$s5a=$row[score5a];

$s6=$row[score6];

$s6a=$row[score6a];

}

 

 

 

?>

 

<?php

$query="SELECT * FROM result";

$result=mysql_query($query);

 

?>

 

 

<H1 align="CENTER"> GROUP A </h1>

<table border="3" align="CENTER" cellspacing="1" cellpadding="1">

<tr>

  <td >NAME</td>

  <td >EMAIL</td>

<td width="5"></td>

  <td >SOUTH AFRICA</td>

  <td >MEXICO</td>

<td width="5"></td>

  <td >URUGUAY</td>

  <td >FRANCE</td>

<td width="5"></td>

  <td >SOUTH AFRICA</td>

  <td >URUGUAY</td>

<td width="5"></td>

  <td >FRANCE</td>

  <td >MEXICO</td>

<td width="5"></td>

  <td >MEXICO</td>

  <td >URUGUAY</td>

<td width="5"></td>

  <td >FRANCE</td>

  <td >SOUTH AFRICA</td>

<td width="5"></td>

  <td >TOTAL</td>

 

<?php

 

while ($row = mysql_fetch_array($result))

{

$f1=$row[firstname];

$e1=$row[emailname];

$r1=$row[result1];

$r1a=$row[result1a];

$r2=$row[result2];

$r2a=$row[result2a];

$r3=$row[result3];

$r3a=$row[result3a];

$r4=$row[result4];

$r4a=$row[result4a];

$r5=$row[result5];

$r5a=$row[result5a];

$r6=$row[result6];

$r6a=$row[result6a];

 

?>

 

 

<?php

if ($r1 == $s1 && $s1a == $r1a)

  $scoreA =+3;

elseif ($r1 == $r1a && $s1 == $s1a)

$scoreA =+1;

elseif ($r1 > $r1a && $s1 > $s1a)

$scoreA =+1;

elseif ($r1 < $r1a && $s1 < $s1a)

$scoreA =+1;

else

$scoreA = 0;

 

 

 

if ($r2 == $s2 && $s2a == $r2a)

  $scoreB =+3;

elseif ($r2 == $r2a && $s2 == $s2a)

$scoreB =+1;

elseif ($r2 > $r2a && $s2 > $s2a)

$scoreB =+1;

elseif ($r2 < $r2a && $s2 < $s2a)

$scoreB =+1;

else

$scoreB = 0;

 

 

if ($r3 == $s3 && $s3a == $r3a)

  $scoreC =+3;

elseif ($r3 == $r3a && $s3 == $s3a)

$scoreC =+1;

elseif ($r3 > $r3a && $s3 > $s3a)

$scoreC =+1;

elseif ($r3 < $r3a && $s3 < $s3a)

$scoreC =+1;

else

$scoreC = 0;

 

 

 

if ($r4 == $s4 && $s4a == $r4a)

  $scoreD =+3;

elseif ($r4 == $r4a && $s4 == $s4a)

$scoreD =+1;

elseif ($r4 > $r4a && $s4 > $s4a)

$scoreD =+1;

elseif ($r4 < $r4a && $s4 < $s4a)

$scoreD =+1;

else

$scoreD = 0;

 

 

if ($r5 == $s5 && $s5a == $r5a)

  $scoreE =+3;

elseif ($r5 == $r5a && $s5 == $s5a)

$scoreE =+1;

elseif ($r5 > $r5a && $s5 > $s5a)

$scoreE =+1;

elseif ($r5 < $r5a && $s5 < $s5a)

$scoreE =+1;

else

$scoreE = 0;

 

 

 

 

if ($r6 == $s6 && $s6a == $r6a)

  $scoreF =+3;

elseif ($r6 = $r6a && $s6 = $s6a)

$scoreF =+1;

elseif ($r6 > $r6a && $s6 > $s6a)

$scoreF =+1;

elseif ($r6 < $r6a && $s6 < $s6a)

$scoreF =+1;

else

$scoreF = 0;

 

 

$sumA = $scoreA + $scoreB + $scoreC + $scoreD + $scoreE + $scoreF;

?>

 

 

 

 

 

 

<tr>

<td ><?php echo $f1; ?></td>

<td ><?php echo $e1; ?></td>

<td width="5"></td>

<td align = "center" colspan="2"><?php echo $scoreA; ?></td>

<td width="5"></td>

<td align = "center" colspan="2"><?php echo $scoreB; ?></td>

<td width="5"></td>

<td align = "center" colspan="2"><?php echo $scoreC; ?></td>

<td width="5"></td>

<td align = "center" colspan="2"><?php echo $scoreD; ?></td>

<td width="5"></td>

<td align = "center" colspan="2"><?php echo $scoreE; ?></td>

<td width="5"></td>

<td align = "center" colspan="2"><?php echo $scoreF; ?></td>

<td width="5"></td>

<td align = "center" colspan="2"><?php echo $sumA; ?></td>

<td width="5"></td>

</tr>

 

<?php

$i++;

}

?>

 

</table><br>

 

 

 

I want to add $sumA to a new database getting each username. i can display however i am not able to add to the database. i think is because is showing as an array? and to add to the database is only getting first $sumA?

 

 

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.