Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with checkboxes in tables

    Hello everyone, I am new to using PHP, and am in need of a little help if anyone would be so kind.

    What I am trying to do is pull data for each record from two fields from a table in a database:

    player_name (the name of the player)
    player_class (what type of character a player plays; e.g. Deathknight, Warrior, Mage)

    for each player, a checkbox is created, so that a user could select which players to view more information about (it will display items and date for "loot" a player has received).

    The functionality of the code seems in place. What I am working on is the format of the data. I feel the best way to display the data would be to have vertical columns for each unique value of player_class as headings, followed by the players who belong to that class type.

    A Mock-up View

    Deathknight Warrior Mage
    Player 1 Player 3 Player 5
    Player 2 Player 4 Player 6

    I am having two problems:
    1) The submit button for some reason appears before the last table, instead of after it.
    2)There is a weird gap between the first and second listing underneath the "Deathknight" table.

    Below is a URL to the webpage, along with the code I have so far (please be kind, I am new and I have not cleaned up my code yet as I am still playing with it to get this to work)

    Any help or suggestions is appreciated, Thanks.

    LINK TO WEBPAGE
    http://www.joshmaun.com/testpage

    CODE:


    $query = "SELECT player_name, player_class FROM player ORDER BY player_class";
    $result = mysql_query($query);
    $num = mysql_numrows($result);
    $i=0;
    $f1=mysql_result ($result,$i,player_name);
    $f2=mysql_result ($result,$i,player_class);
    $old_class=$f2;
    ?>
    <table border="0" style="display:inline">
    <th><?php echo $f2; ?></th>
    <?php
    while ($i < ($num-1)) {
    if ($old_class != $f2) {
    $old_class = $f2
    ?>
    <table border="0" style="display:inline">
    <th><?php echo $f2; ?></th>
    <?php
    }
    ?>
    <tr><td>
    <form action="welcome.php" method="post">
    <input type="checkbox" name="players[] " value="<?php echo $f1; ?>" />
    <?php echo $f1; ?>
    </td></tr>
    <?php
    $i++;
    $f1=mysql_result ($result,$i,player_name);
    $f2=mysql_result ($result,$i,player_class);
    }
    ?>
    <input type="submit" value="Submit" />
    </form>
    </BODY>
    </HTML>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    To begin with, add a suitable DOCTYPE at the top. I'd recommend
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    . Then validate your page using http://validator.w3.org/ and fix the markup errors, if any.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I followed your advice, and it fixed the first of my 2 main issues, along with exposing a lot of mark up errors. Thanks a bunch for your input.

    "Errors found while checking this document as HTML 4.01 Strict!
    Result: 152 Errors, 32 warning(s) "

    I had no idea about DOCTYPE, but am glad you told me

    Anybody have an idea about the submit button? (Gonna be going through the above errors which I guess could point me to the problem with the location of the submit button, but I'll take any ideas while I'm working through it)

  • #4
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well my problems are fixed! (for now =P)

    I had a lot of mark up errors, mostly not closing tags. I decided to start from the bottom, (since that's around the area where the submit button is), closed the <table> tag, refreshed the page, and now it appears exactly how I want it to!

    I'll spend tomorrow fixing the markup to proper standards, and doing a control break to change color of text per class.

    Thanks again!

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Good!
    FYI, when using an HTML doctype, you shouldn't close your tags like input,meta,link with a self close. Or just switch to an xhtml doctype.

    PS: Using tables for making layout is very bad. Tables are basically for showing tabular data. Also, have a look at http://www.alistapart.com/articles/p...cessibleforms/ to see how to make an accessible form.
    Last edited by abduraooft; 01-02-2010 at 11:11 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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