![](https://forums.phpfreaks.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
Canman2005
-
Posts
669 -
Joined
-
Last visited
Never
Posts posted by Canman2005
-
-
Hi all
I have the following javascript maths being actioned from the input of a html form
if (document.myform.fieldr.value && document.myform.fieldw.value && document.myform.fieldjj.value && document.myform.fieldkk.value) { fieldrval = document.myform.fieldr.value fieldwval = document.myform.fieldw.value fieldjjval = document.myform.fieldjj.value fieldkkval = document.myform.fieldkk.value calc1 = fieldwval - fieldrval calc2 = calc1 / fieldwval calc3 = fieldjjval - fieldkkval calc4 = calc3 / fieldjjval document.myform.fieldy.value=calc2.calc4 }
At the moment this wont work because of the full stop between
calc2.calc4
on the last line of code
How can I output the value with a full stop in between calc2 and calc4?
Hope that makes sense
Thanks
Dave
-
Managed to get it right, in the end it was
printf('% (%0.1f<br>', $x, $pc/10);
Thanks for all the help
-
oh thanks mate.
what would be the best way to just display the value, so
20 (80.0)
2 (8.0)
8 (32.0)
4 (16.0)
5 (20.0)
would be come
80.0
8.0
32.0
16.0
20.0
and then deviding them by 10
is there a prefered way of doing that?
-
How can I remove the % sign from the code above outputs?
-
cool, guess I could just devide it by 10 to get a average out of 10
or is there a more logical way of doing that
-
Plus i'm not sure that's producing the right results, discomatt comments with outputting the following as an example looked right
200 (10)
150 (7.5)
90 (4.5)
50 (2.5)
10 (0.5)
I mean, that's the kinda result I want to product
any good ideas anyone?
-
Cool, well that produced something, but do you know how to get it to output as 1 didget after the decimal place, so
0.04
becomes
0.4
-
any ideas? still at it with no luck yet
-
Hi all
I tried altering it to
$stuff "SELECT levelcode FROM levels"; $levels = array(); while ($stuff = $stuff) { $levels[] = $stuff['levelcode']; } $total = array_sum($levels); foreach ($levels AS $value) { echo $value.' = '.round($value / $total, 2).'<br />'; }
not sure if I did that right, but it doesnt seem to produce any result at all.
Can anyone help?
-
discomatt, what query should I use with that?
akitchin, your query wants me to do a GROUP and if I do that, it doesnt seem to add up multiple values assigned to that userid
any ideas?
-
any ideas?
-
Well I guess im just trying to get a score out of 10 depending on their value compared to other in the table
-
Yes, I think that method would work, how would it be possible to do with the top value being 10%
-
Hi all
Wondering if someone can help.
I have the following query
$sql = "SELECT * FROM `levels`"; $show = @mysql_query($sql,$connection) or die(mysql_error()); while ($row = mysql_fetch_array($show)) { print $row['levelcode'].'<br>'; }
which returns a list of level codes, the output at the moment looks like
72
234
4
7655
43
What I want to do is display next to each code returned, an average score out of 10 compared to the other codes.
I don't 100% know to write the query or even what the result should be, but it would look something like
72 - (2.6)
234 (7.4)
4 (0.4)
7655 (9.9)
43 (1.4)
Of course those numbers are incorrect, hence why I am trying to work out the query to use.
I thought maybe it would be something like
select count(*) as cnt, SUM(levelcode) as sum, (SUM(levelcode)/count(*)) as avg FROM levels;
but that doesnt stick to an average of 10, plus it gives an average for the whole database and not each row individually, plus it gives 4 digits result after the fullstop, such as 27.9375, whereas I need to stick to 1 digit such as 5.4
Could someone please help me work this one out, it's slowly making me dumber
Thanks
Dave
-
Just stuck trying to get just the rows of the table "members" that have a particular code, but then auto skipping the ones that dont have that code.
it cant work with
$return = "SELECT id, name, code FROM members WHERE id = '".$id."' AND code = '' ";
because as soon as a row is returned without the correct code you are asking it for, it simply returns an empty row.
-
If the code doesnt exist on the row it's returning I guess it almost needs to skip that row and move onto the next, but the mods i've tried have not worked yet.
-
Yep, that seems to do the job until you reach a row which doesnt have that code im asking for.
Because you're grabbing the next ID in the sequence, if that ID it returns doesnt equal what im asking then it just displays nothing.
If that makes sense?
Any ideas?
-
Thanks Minase
The problem is that the code is held in the table "members" and not "scores", therefore that QUERY wouldn't be able to find the field code.
Do you have anything else up your sleve you maybe able to advise on?
Thanks
-
Minase
Your code worked spot on.
I'm wondering if anyone can help me further this code, basically I want to add another field to the "members" table called "code", so the table would look like
ID NAME CODE
1 David A
2 Bob B
3 Sarah A
and then I want to alter the QUERY so that it only selects members with A in the code field and skips any member with B in their CODE field.
Can anyone help?
Masssive thanks to everyone who has helped so far
Dave
-
Thanks again Minase
-
afraid it still returns a row with a EMPTY value for some reason, not sure why
my little mod seems to have solved it
thanks for all your help
-
It's exactly like your code.
I added
if(isset($_GET['start'])) { $id = 1; }
just under
$id = $r['member_id'] + 1;
which seems to work
-
Thanks very much
It just seems when you reach the last row of the members table, it returns an empty ID
I think that might be because we get the last ID of the members table and add 1 and that ID wouldnt exist
-
It doesn't seem to be for me, I have the following
$select = mysql_query("SELECT * FROM scores ORDER BY ID DESC LIMIT 1"); $r = mysql_fetch_array($select); $id = $r['member_id'] + 1; if(!mysql_query("SELECT id, name FROM members WHERE id = '".$id."' ")) { $return = "SELECT id, name FROM members ORDER BY id ASC LIMIT 1"; } else { $return = "SELECT id, name FROM members WHERE id = '".$id."' "; } $show = @mysql_query($return,$connection) or die(mysql_error()); while($r = mysql_fetch_array($show)) { print $r['name'] }
But when it gets to "member" ID number 3 (which is the last one) it seems to not display anything, which makes me think it isn't looping.
Any ideas?
[SOLVED] Javascript Maths - Using a full stop
in Javascript Help
Posted
any ideas anyone?