Jump to content


Photo

Caculation error


  • Please log in to reply
5 replies to this topic

#1 DanielBourne

DanielBourne
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 30 April 2006 - 12:13 PM

This from needs to total up all the inputs and rank it then goto the ranked page but somehow it does not add up.

Any help would be much appreciated, the code is as follows :

<?php
function loader()
{
?>
<html>
<head>
<body>
Please Wait Loading...
</body>
</head>
</html>

<?php
}
?>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$question[0] = $_POST['Q[0]'];
$question[2] = $_POST['Q[2]'];
$question[3] = $_POST['Q[3]'];
$question[4] = $_POST['Q[4]'];
$question[5] = $_POST['Q[5]'];
$question[6] = $_POST['Q[6]'];
$question[7] = $_POST['Q[7]'];
$question[8] = $_POST['Q[8]'];
$question[9] = $_POST['Q[9]'];
$question[10] = $_POST['Q[10]'];
$question[11] = $_POST['Q[11]'];
$question[12] = $_POST['Q[12]'];
$question[13] = $_POST['Q[13]'];
$question[14] = $_POST['Q[14]'];
$question[15] = $_POST['Q[15]'];
$question[16] = $_POST['Q[16]'];
$question[17] = $_POST['Q[17]'];
$question[18] = $_POST['Q[18]'];
$question[19] = $_POST['Q[19]'];
$question[20] = $_POST['Q[20]'];
$question[21] = $_POST['Q[21]'];
$question[22] = $_POST['Q[22]'];
$question[23] = $_POST['Q[23]'];
$question[24] = $_POST['Q[24]'];
$question[25] = $_POST['Q[25]'];
$question[26] = $_POST['Q[26]'];
$question[27] = $_POST['Q[27]'];
$question[28] = $_POST['Q[28]'];
$question[29] = $_POST['Q[29]'];
$question[30] = $_POST['Q[30]'];
$question[31] = $_POST['Q[31]'];
$question[32] = $_POST['Q[32]'];
$question[33] = $_POST['Q[33]'];
$question[34] = $_POST['Q[34]'];
$question[35] = $_POST['Q[35]'];
$question[36] = $_POST['Q[36]'];
$question[37] = $_POST['Q[37]'];
$question[38] = $_POST['Q[38]'];
$question[39] = $_POST['Q[39]'];
$question[40] = $_POST['Q[40]'];
$question[41] = $_POST['Q[41]'];
$question[42] = $_POST['Q[42]'];
$question[43] = $_POST['Q[43]'];

$total = 0;
for ($i = 0; $i < 43; $i++)
{
$question[$i] = $_POST['Q['.$i.']'];
$total += $question[$i];
}

if ($total < 43)
{
echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=http://www.technowledgeable.com/ICTPE/rating1.html'>";
}
else if ($total < 88) // So on and so forth
{
loader();
echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=http://www.technowledgeable.com/ICTPE/rating2.html'>";
}
else if ($total < 132)
{
loader();
echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=http://www.technowledgeable.com/ICTPE/rating3.html'>";
}
else if ($total < 176)
{
loader();
echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=http://www.technowledgeable.com/ICTPE/rating4.html'>";
}
}
?>

Thank you

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 30 April 2006 - 01:16 PM

You have already transferred the data from the $_POST array to the $question array, so why do it again?

$total = 0;
foreach ($question as $val)
{
          $total += $val;
}

What does the form code look like?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 DanielBourne

DanielBourne
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 30 April 2006 - 01:40 PM

[!--quoteo(post=370092:date=Apr 30 2006, 08:16 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 30 2006, 08:16 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You have already transferred the data from the $_POST array to the $question array, so why do it again?

$total = 0;
foreach ($question as $val)
{
          $total += $val;
}

What does the form code look like?
[/quote]

ok this is the from code


<p>Interactive whiteboards with data projectors
<input name="Q[0]" type="text" id="Q[0]" size="5">
</p>
<p>Departmental Laptop/PDA
<input name="Q[1]" type="text" id="Q[1]" size="5">
</p>
<p>Individual laptops/PDA
<input name="Q[2]" type="text" id="Q[2]" size="5">
</p>
<p>Learner laptops/PDA
<input name="Q[3]" type="text" id="Q[3]" size="5">
</p>
<p>Data projectors on their own
<input name="Q[4]" type="text" id="Q[4]" size="5">
</p>
<p>Digital still cameras
<input name="Q[5]" type="text" id="Q[5]" size="5">
</p>
<p>Digital video cameras &nbsp;
<input name="Q[6]" type="text" id="Q[6]" size="5">
</p>
<p>Access to Internet cameras
<input name="Q[7]" type="text" id="Q[7]" size="5">
</p>
<p>Access to appropriate software
<input name="Q[8]" type="text" id="Q[8]" size="5">
</p>
<p>Access to extensive computer lab time
<input name="Q[9]" type="text" id="Q[9]" size="5">
</p>
<p>PE ICT Budget
<input name="Q[10]" type="text" id="Q[10]" size="5">
</p>
<p><strong>How often do you use the resources listed below?</strong></p>
<p>Please rate against the following criteria.</p>
<p>1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>Seldom&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Occasionally &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Often&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Daily</p>
<p>Interactive whiteboards with data projectors
<input name="Q[11]" type="text" id="Q[11]" size="5">
</p>
<p>Data projectors on their own
<input name="Q[12]" type="text" id="Q[12]" size="5">
</p>
<p>Digital still cameras &nbsp;
<input name="Q[13]" type="text" id="Q[13]" size="5">
</p>
<p>Digital video cameras &nbsp;
<input name="Q[14]" type="text" id="Q[14]" size="5">
</p>
<p>Web sites to support PE
<input name="Q[15]" type="text" id="Q[15]" size="5">
</p>
<p>Software to support PE
<input name="Q[16]" type="text" id="Q[16]" size="5">
</p>
<p>Laptops/PDA
<input name="Q[17]" type="text" id="Q[17]" size="5">
</p>
<p>Computer laboratory
<input name="Q[18]" type="text" id="Q[18]" size="5">
</p>
<p><strong>Please select the year groups in your school where you feel ICT is well used to support PE?</strong></p>
<p>
<input type="checkbox" name="checkbox" value="checkbox">
Key stage 2 <span class="style1">....... </span>
<input type="checkbox" name="checkbox2" value="checkbox">
Key stage 3 <span class="style1">...........</span>
<input type="checkbox" name="checkbox3" value="checkbox">
Key stage 4 </p>
<p><strong>How confident are you with the use of ICT equipment for PE?</strong></p>
<p>Please rate against the following criteria.</p>
<p><span class="style1">...........</span>1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="style1">...</span>&nbsp;5</p>
<p>Very confident &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Confident &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Competent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Have had training &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Need training</p>
<p>&nbsp;</p>
<p>Interactive whiteboards with data projectors&nbsp;
<input name="Q[19]" type="text" id="Q[19]" size="5">
</p>
<p>Data projectors on their own
<input name="Q[20]" type="text" id="Q[20]" size="5">
</p>
<p>Digital still cameras
<input name="Q[21]" type="text" id="Q[21]" size="5">
</p>
<p>Digital video cameras&nbsp;&nbsp;
<input name="Q[22]" type="text" id="Q[22]" size="5">
</p>
<p>Internet / web sites
<input name="Q[23]" type="text" id="Q[23]" size="5">
</p>
<p>Software to support PE
<input name="Q[24]" type="text" id="Q[24]" size="5">
</p>
<p>Laptops/PDA
<input name="Q[25]" type="text" id="Q[25]" size="5">
</p>
<p>Computer laboratory
<input name="Q[26]" type="text" id="Q[26]" size="5">
</p>
<p><strong>What support would you find useful for developing the use ICT within PE?</strong></p>
<p>Please rate against the following criteria.</p>
<p><span class="style1">....</span>1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4 &nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>Limited&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Reasonable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Good&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Excellent</p>
<p>&nbsp;</p>
<p>Twilight training sessions/workshops
<input name="Q[27]" type="text" id="Q[27]" size="5">
</p>
<p>INSET training
<input name="Q[28]" type="text" id="Q[28]" size="5">
</p>
<p>ICT and PE courses &nbsp;&nbsp;
<input name="Q[29]" type="text" id="Q[29]" size="5">
</p>
<p>Observation of demonstration lessons
<input name="Q[30]" type="text" id="Q[30]" size="5">
</p>
<p>Guidance on useful web sites
<input name="Q[31]" type="text" id="Q[31]" size="5">
</p>
<p>Guidance on useful software
<input name="Q[32]" type="text" id="Q[32]" size="5">
</p>
<p>Access to video clips showing effective practice
<input name="Q[33]" type="text" id="Q[33]" size="5">
</p>
<p>Access to an on-line support network &nbsp;
<input name="Q[34]" type="text" id="Q[34]" size="5">
</p>
<p><strong>Please indicate to what extent you agree or disagree with the following statements</strong><br>
<strong>about ICT</strong></p>
<p>Please rate against the following criteria.</p>
<p><span class="style1">&nbsp;..........</span>1<span class="style1">............</span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="style1">.........</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;<span class="style1">.........</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4</p>
<p>Agree Strongly&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tend to Agree&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tend to Disagree&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Disagree Strongly </p>
<p>My department can get access to ICT equipment for pupils when needed
<input name="Q[35]" type="text" id="Q[35]" size="5">
</p>
<p>The ability to deliver ICT through PE has improved teaching and learning in the subject
<input name="Q[36]" type="text" id="Q[36]" size="5">
</p>
<p>My department has adequate technical support for our use of ICT
<input name="Q[37]" type="text" id="Q[37]" size="5">
</p>
<p>My department has not had sufficient training in the use of ICT
<input name="Q[38]" type="text" id="Q[38]" size="5">
</p>
<p>Too much emphasis is placed on ICT within the curriculum for PE
<input name="Q[39]" type="text" id="Q[39]" size="5">
</p>
<p>Our PE department has good relationship with commercial partners
<input name="Q[40]" type="text" id="Q[40]" size="5">
</p>
<p>Our PE department receives extensive support from the school for ICT
<input name="Q[41]" type="text" id="Q[41]" size="5">
</p>
<p>ICT use is essential to the future of PE
<input name="Q[42]" type="text" id="Q[42]" size="5">
</p>
<p>Through ICT PE enjoys good cross curricula links in my school
<input name="Q[43]" type="text" id="Q[43]" size="5">

but i have now changed the php to (as u suggested):

<?php
function loader()
{
?>
<html>
<head>
<body>
Please Wait Loading...
</body>
</head>
</html>

<?php
}
?>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$question = $_POST;

$total = 0;
for ($i = 0; $i < 43; $i++)
{
$question[$i] = $_POST['Q['.$i.']'];
$total += $question[$i];
}

if ($total < 43)
{
loader();
echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=http://www.technowledgeable.com/ICTPE/rating1.html'>";
}
else if ($total < 88)
{
loader();
echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=http://www.technowledgeable.com/ICTPE/rating2.html'>";
}
else if ($total < 132)
{
loader();
echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=http://www.technowledgeable.com/ICTPE/rating3.html'>";
}
else if ($total < 176)
{
loader();
echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=http://www.technowledgeable.com/ICTPE/rating4.html'>";
}
}
?>


Any ideas

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 30 April 2006 - 01:46 PM

Replace this

$question[0] = $_POST['Q[0]'];
$question[2] = $_POST['Q[2]'];
$question[3] = $_POST['Q[3]'];
$question[4] = $_POST['Q[4]'];
...
...
...
$question[43] = $_POST['Q[43]'];

with

$question = $_POST['Q'];

then

$total = 0;
foreach ($question as $val)
{
          $total += $val;
}

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 DanielBourne

DanielBourne
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 30 April 2006 - 02:04 PM

thanks a million it works brilliant ,

I owe you one i have been struggling with this all weekend, but have learned a lot from you guys.



#6 DanielBourne

DanielBourne
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 30 April 2006 - 02:19 PM

Ok thats done but when i use the insert command to actually store that data in mysql database it does not store it at all. all other the functionality works though




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users