Jump to content

tomd79

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Posts posted by tomd79

  1. <?php
    
    
    $names = $_POST['names'];
    
    if ($names ==  NULL ) {
    die("<div id='error'>No names were selected! <br /> Please select some names..</div>");
    }
    
    else
    
    shuffle($names);
    
    $selected = array_rand($names, 1);
    
    echo "$selected"
    
    
    ?>
    

     

    This displays the array number not the value.. what do I do to get the value i.e. the actual name?

     

     

    Thanks

  2. if this is on the index page.

     

    is it posting to itself?

     

    <form method="post" action="index.php"/> 
    

     

    If your copying the code to another page.. does the action not need updating or are you wanting it to go to index.php

  3. - the very first time I used php I had the dev file locally.. and ran it through FireFox,, took me a little while to actually twig i needed it running on apache.. which for me meant a remote host.. 

     

    certainly isn't obvious to someone completely new to php

  4. in my code I have a simple if else..

     

    if (a==NULL) {
    die "bad robot";
    {
    
    else
    
    blah blah blah
    

     

    I want to be able to test 2 conditions in the if i.e.

    if (a==NULL & b==SomeValue) {
    die "bad robot";
    {
    
    else
    
    blah blah blah
    

     

    been searching and come up blank.. anyone show me how?

  5. would anyone help with this as I'm pulling my hair out and getting nowhere!!

     

    This is a 'simple' team picker for our works 5 aside.. its working, but I have tried to add a field to the form where a guest players name can be inserted.. The problem is if no guest is playing the empty field is still sent, and counted in the PHP..

     

    The html form:

    <form action="sort.php" method="POST">
    <input type="checkbox" name="players[]" value="name"  /> name <br />
    <input type="checkbox" name="players[]" value="name1"  /> name 1<br />
    <input type="checkbox" name="players[]" value="name2"  /> name 2<br />
    <input type="checkbox" name="players[]" value="name3"  /> name 3<br />
    <input type="text" name="players[]"  /> Enter guests name<br />
    <br />
    <input type="submit" value="Pick the teams!">
    </form><br />
    

     

    The php:

    <?php
    shuffle( $_POST['players'] );
    $player_count = count( $_POST['players'] );
    $team_size = ceil( $player_count / 2 );
    list( $team1, $team2 ) = array_chunk( $_POST['players'], $team_size );
    echo "<h2>Team 1</h2>";
    echo "<b>Player count:</b> " . count( $team1 ) . "<br />";
    echo "<b>Player list:</b>";
    echo "<ul>";
    
    foreach ( $team1 as $player ) {
    echo "<li>$player</li>";
    }
    echo "</ul>";
    
    echo "<h2>Team 2</h2>";
    echo "<b>Player count:</b> " . count( $team2 ) . "<br />";
    echo "<b>Player list:</b>";
    echo "<ul>";
    foreach ( $team2 as $player ) {
    echo "<li>$player</li>";
    }
    echo "</ul>";
    
    ?>
    

     

    I have tried alsorts but cant get the empty elements removed before the shuffle.. help would be greatly appreciated.

  6. Hi all

     

    I'm guessing this is another real simple question!!

     

    I have a HTML form with a number of check boxes that creates an array for my php. The form has one text field for a user to add a unique entry not available from the existing check boxes (see html code)

     

    <input type="checkbox" name="players[]" value="somevalue"  /> some value<br />
    <input type="checkbox" name="players[]" value="somevalue1"  /> some value 1<br />
    <input type="text" name="players[]"  /> Please input players name<br />
    

     

    The problem I'm having is the text input is being parsed in the array even if its empty (i.e User doen't want to add another unique value)...

     

    What I want to happen is the text input is parsed if a value is entered but is simply ignored if the text input is empty. I do NOT want it to report an error is the text input is empty.....

     

    I've been browsing the web and can see loads of documention on form validation, but everything seems to be about validating inputs or throwing errors. I can't find anything on simply ignoring empty fields and making sure they don't get submitted...

     

    My guess is that the $post has to send the empty text input, so the PHP will have to have a check to look for empty inputs and disregard them?

  7. Hi,

     

    Sorry for taking a while to get back to you!

     

    1. There will only ever be 2 team.

    2. The number of players playing each week varies (and they can be uneven numbers)

    3. The players are stored in a list of check boxes in a html form

     

    the form holding the names:

    <form action="sort.php" method="POST">
    <input type="checkbox" name="players[]" value="name0"  /> name 0<br />
    <input type="checkbox" name="players[]" value="name1"  /> name 1<br />
    <input type="checkbox" name="players[]" value="name2"  /> name 2<br />
    <input type="checkbox" name="players[]" value="name3"  /> name 3<br />
    <input type="checkbox" name="players[]" value="name4"  /> name 4<br />
    <input type="checkbox" name="players[]" value="name5"  /> name 5<br />
    <input type="checkbox" name="players[]" value="name6"  /> name 6<br />
    <input type="checkbox" name="players[]" value="name7"  /> name 7<br />
    <input type="checkbox" name="players[]" value="name8"  /> name 8<br />
    <input type="checkbox" name="players[]" value="name9"  /> name 9<br />
    <input type="checkbox" name="players[]" value="name10"  /> name 10<br />
    <input type="checkbox" name="players[]" value="name11"  /> name 11<br />
    <input type="checkbox" name="players[]" value="name12"  /> name 12<br />
    <input type="checkbox" name="players[]" value="Guest 1"  /> Guest 1: ()<br />
    <input type="checkbox" name="players[]" value="Guest 2"  /> Guest 2: ()<br />
    
    <br />
    <input type="submit" value="Pick the teams!">
    </form><br />
    

     

     

    So its something like:

    Select players from list:

    Pass selected players to PHP array:

    Randomly assign one player at a time to group A or group B:

    When the array is empty, display the groups with their assignments..

     

    Thanks again so much for your help!

    Tom

  8. hi again,

    at work we play 5 aside football each week.

    There are 20 people who play, but not all play every week.. So I wanted a form which lists all the possible players, we can tick the check boxes next to those who CAN play that week, then submit. This would then return the selected played assigned Randomly to either Team A or Team B..

     

    I hope that makes sense..

     

    And thanks so much for taking the time to help, I've only got as far as printing the array from the form and I've already picked up loads!

  9. Thanks for the further input, I think this is a case or running before walking! :/

    I have taken a step back and trying to just get an array into PHP.. 

     

    My form to set up the array in the html

    <form name="players[] "action="sort.php" method="POST">
    <input type="checkbox" name="players[]" value="1"  /> 1<br />
    <input type="checkbox" name="players[]" value="2"  /> 2<br />
    <input type="checkbox" name="players[]" value="3"  /> 3<br />
    <input type="checkbox" name="players[]" value="4"  /> 4<br />
    <input type="checkbox" name="players[]" value="5"  /> 5<br />
    <input type="submit" value="Pick the teams!">
    </form><br />
    

     

    The code in my sort PHP print the content of the array (to see if Im doing the form bit right)

    <?php
    $players = $_POST["players"];
    echo $players;
    ?>
    

     

    This simply prints "Array" in the subsequent HTML!?

     

    Anyone tell me where Im goiung wrong?

     

    thanks so much

     

     

     

  10. Hi, thanks for the input..

     

    Before I start reading on array shuffle, can I ask 2 things.. Will this allow me to assign to 2 separate groups? and will this still work if the user only picks say 15 of the options available?

     

    basically I want the user to choose who will be playing the football mini league that week and split the users into 2 teams..

  11. Hi,

     

    New to PHP, I have been reading but am in serious need of some direction/help.......

     

    I have a simple HTML check box form with 20 options for the user to select. All I want is to have the selected options divided randomly into 2 groups and displayed back to the user.. PHP seems like the right thing to do this in, but I'm completely stuck..

     

    Can anyone offer me some help guidance?

     

    Thanks

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