Jump to content

Canman2005

Members
  • Posts

    669
  • Joined

  • Last visited

    Never

Posts posted by Canman2005

  1. 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

  2. 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?

     

  3. 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?

  4. 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?

  5. 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

  6. 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.

  7. 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?

  8. 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

  9. 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

  10. 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

  11. 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?

×
×
  • 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.