Jump to content


Photo

Conditional Statements


  • Please log in to reply
1 reply to this topic

#1 wickednawh

wickednawh
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 16 June 2006 - 12:18 AM

Greetings,

I'm attempting to write a "process of elimination" script so to speak. I have the conditionals set but once it finds a true statement it will stop. I want it to display all true statements isntead of just one.

Basic Concept: Number's 1-3.
I am using a form with 3 check box buttons and will submit it to my php script.

The Problem:
The script will do exactly what I want it to do when I select just one value via the form submit to php script (for example, 1, php script will say i have numbers 2 and 3 left to use). But when I choose value's 1 then 2, it will process it only as if I have only selected 2 and will then display numbers 1 and 3, despite me already chosing 1 and 2 instead of my desired result of saying I only have the number 3 left to use.

Desired outcome:
I want it to process both values, say 1 and 2 to tell me I only have number 3 left to use. I will evently have another box telling me the numbers I used as well next to the "number's left" section. But i have no idea how to make it execute more than 1 truth. I've tried using while, if, if else statements, but not of them have seemed to work for me. I'm not sure what to do, I've read up a bit and bought a book, but still nothing. :| Eventually I will to expand this to number's 1-6, but for explanation purposes, i'm saying 1-3.

Here is what i have so far.

My Html looks like this...
<input type="checkbox" name="player" value="1"> 1
<input type="checkbox" name="player" value="2"> 2
<input type="checkbox" name="player" value="3"> 3

The form and submit tags excluded. My processing script looks like this:


Your Numbers Left:<br>


<?php

switch ($player) {

# Player's Number's Left
    case '1':
        echo ' ';
    break;
    default:
        echo '1, ';
}

switch ($player) {

# Player's Number's Left
    case '2':
        echo ' ';
    break;
    default:
        echo '2, ';
}

switch ($player) {

# Player's Number's Left
    case '3':
        echo ' ';
    break;
    default:
        echo '3, ';
}

?>


How do I make it say I have the number 3 left to use after selecting 1 and 2 on the form. I know something along the lines of "if $player == 2 && == 3" might get what I want but that means I have to write out every possible scenario with number's 1-6. For example, I to choose 1, 2, 5, 6. I want it to tell me I have only 3, 4 left to use. And eventually tell me I already used 1, 2, 5, 6. Is there anyway I can do this via without having to write all possible number selections with 1-6 (I think that's 720 different possible selections till the final number remains), in php or do I need to look into another language?

Thanks for the help!

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 June 2006 - 01:16 AM

Change this:
<input type="checkbox" name="player" value="1"> 1
<input type="checkbox" name="player" value="2"> 2
<input type="checkbox" name="player" value="3"> 3

To this:
<input type="checkbox" name="player[]"> 1
<input type="checkbox" name="player[]"> 2
<input type="checkbox" name="player[]"> 3
That will generate an array of player values that can be processed as you see fit.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users