Jump to content

Archived

This topic is now archived and is closed to further replies.

wickednawh

Conditional Statements

Recommended Posts

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...
[code]
<input type="checkbox" name="player" value="1"> 1
<input type="checkbox" name="player" value="2"> 2
<input type="checkbox" name="player" value="3"> 3
[/code]

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

[code]

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, ';
}

?>

[/code]

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!

Share this post


Link to post
Share on other sites
Change this:
[code]<input type="checkbox" name="player" value="1"> 1
<input type="checkbox" name="player" value="2"> 2
<input type="checkbox" name="player" value="3"> 3[/code]

To this:
[code]<input type="checkbox" name="player[]"> 1
<input type="checkbox" name="player[]"> 2
<input type="checkbox" name="player[]"> 3[/code]
That will generate an array of player values that can be processed as you see fit.

Share this post


Link to post
Share on other sites

×

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.