www.webdeveloper.com
Results 1 to 6 of 6

Thread: PHP Help - Consecutive Numbering

  1. #1
    Join Date
    Oct 2012
    Posts
    4

    PHP Help - Consecutive Numbering

    I'm trying to hide some specific <tr> rows on the registration form in Virtuemart that are not needed, but there is no way to 'target' them as it uses the same piece of coding to create all the rows.

    What we have at the moment is:

    echo ' <table class="adminForm user-details">' . "\n";
    $_table = true;
    }
    echo ' <tr>' . "\n";
    echo ' <td class="key" title="'.$_field['description'].'" >' . "\n";
    echo ' <label class="' . $_field['name'] . '" for="' . $_field['name'] . '_field">' . "\n";
    echo ' ' . $_field['title'] . ($_field['required'] ? ' *' : '') . "\n";

    Where the td class is simply called "key" and all td are then called the same. We are trying to add in some consecutive lettering functionality so that each row then gets labelled with a consecutive number.

    We've tried adding this into the top of the page:

    <?php
    // array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');
    foreach (range('a', 'z') as $letter)
    ?>
    Which does generate consecutive letters, and then this change to the code:

    echo ' <td class="key td-id-'.$letter.'" title="'.$_field['description'].'" >' . "\n";

    Any thoughts on how to get this to work?

    Thanks in advance!

  2. #2
    Join Date
    Jul 2012
    Location
    Vancouver
    Posts
    61
    auto increment of ++ works on lettering. start with $letter = "a";

    once you've used it, $letter++; and it turns to b.
    Code:
    $letter = "a";
    foreach($x AS $y) {
    echo ' <td class="key td-id-'.$letter.'" title="'.$_field['description'].'" >' . "\n";
    $letter++;
    }

  3. #3
    Join Date
    Oct 2012
    Posts
    4
    I tried that, but it hides the first column, what did I do wrong?:

    echo ' <table class="adminForm user-details">' . "\n";
    $_table = true;
    }
    echo ' <tr>' . "\n";


    $letter = "a";
    foreach($x AS $y) {
    echo ' <td class="key td-id-'.$letter.'" title="'.$_field['description'].'" >' . "\n";
    $letter++;
    }

    echo ' <label class="' . $_field['name'] . '" for="' . $_field['name'] . '_field">' . "\n";
    echo ' ' . $_field['title'] . ($_field['required'] ? ' *' : '') . "\n";
    echo ' </label>' . "\n";
    echo ' </td>' . "\n";
    echo ' <td>' . "\n";
    echo ' ' . $_field['formcode'] . "\n";
    echo ' </td>' . "\n";
    echo ' </tr>' . "\n";
    }
    }

    if ($_table) {
    echo ' </table>' . "\n";
    }

  4. #4
    Join Date
    Oct 2012
    Posts
    4
    OK, I found a quick and easy solution:

    echo ' <tr class="key td-id-' . $_field['name'] . '">' . "\n";

    I just added the existing ' . $_field['name'] . ' code to the tr and I was then able to target this in the way I wanted.

    Thanks for the help!

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,241
    If feasible, I would make that an ID attribute instead of CLASS, since that is its purpose: to uniquely identify that element. So you might keep the single class name for all those elements so that you can use that for common CSS attributes, then access the specific ID(s) for special treatment of those elements.
    PHP Code:
    echo ' <tr class="key" id="'.$_field['name'].'">' 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Oct 2012
    Posts
    4
    Good point, thanks for all the help!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles