SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict jamus's Avatar
    Join Date
    Jul 2004
    Location
    Devon, UK
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Bavery score - Check box values add up for query?

    Hi,
    I'm trying to compare how brave someone is to a database of fictional characters. The characters in the database have a value for bravery out of 10. And here's the problem!

    I'm working out someones bravery by getting them to tick check boxes.

    "Ever taimed a lion?"
    "Ever done public speaking?"

    Each check box might have a different value.

    How do I make these check boxes "add up" so I can use the "total" in the query?

    Hope this makes sense!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    what language are you processing the form submission with? asp? coldfusion? php?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict jamus's Avatar
    Join Date
    Jul 2004
    Location
    Devon, UK
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OOpps! sorry. I'm using PHP!

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    okay, moving to php forum
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Addict jamus's Avatar
    Join Date
    Jul 2004
    Location
    Devon, UK
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, thank you!

  6. #6
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <form action="addBravery.php" method="post">
    <input type="checkbox" name="lion" value="1">
    <input type="checkbox" name="plane" value="1">
    <input type="checkbox" name="gotShot" value="1">
    <input type="checkbox" name="EatenWorms" value="1">
    ...
    </form>

    ---
    <!--/*addBravery.php*/-->
    $lion = $_POST['lion'];
    ...

    echo "$lion"; //just to show that $lion=1;

    $bravery = $lion + $plane ...;

    echo "$bravery";
    ---

    That's how I would start, if it doesn't work, we'll figure out something else, I'm not positive that an unchecked checkbox vaule is 0 or null, it may have a value otherwise.

  7. #7
    SitePoint Addict jamus's Avatar
    Join Date
    Jul 2004
    Location
    Devon, UK
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I found a javascript script that might work. Should i steer clear of that and workk out the php?

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    if you want to show the user what his total bravery score is before submitting, then yes, use the javascript

    otherwise, since you're going to have to do it again anyway on the server, i wouldn't bother with the javascript
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    SitePoint Addict jamus's Avatar
    Join Date
    Jul 2004
    Location
    Devon, UK
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again.

    For any searching I found this http://www.madirish.net/tech.php?section=1&article=7 Yes. I do want to find finding the total before submiting the form so this should work a treat.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •