#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    4
    Rep Power
    0
    I am developing a table where one cell is a multiple button list of shortcuts that are pasted into another <textarea> in the table.
    All has gone well until I try to execute my for loop, which a section from inside the table has been included:
    // set up arrays to hold our button labels
    $ButtonLabel[0] = "COMP";
    $ButtonLabel[1] = "RTP";
    $ButtonLabel[2] = "FPL";
    $ButtonLabel[3] = "TVC";
    $ButtonLabel[4] = "OL";
    $ButtonLabel[5] = "LIP";
    $ButtonLabel[6] = "SIP";
    $ButtonLabel[7] = "RR";
    $ButtonLabel[8] = "RDY";
    // set up array to hold our button values
    $ButtonValue[0] = "Complete";
    $ButtonValue[1] = "Ready to Place";
    $ButtonValue[2] = "FPL";
    $ButtonValue[3] = "TV Cable";
    $ButtonValue[4] = "On Log";
    $ButtonValue[5] = "Line In Progress";
    $ButtonValue[6] = "Spl In Progress";
    $ButtonValue[7] = "Removal Ready";
    $ButtonValue[8] = "Ready Work";
    // set up array to hold our button _name_ values
    $ButtonName[0] = "compnote";
    $ButtonName[1] = "rptnote";
    $ButtonName[2] = "fplnote";
    $ButtonName[3] = "tvcnote";
    $ButtonName[4] = "olnote";
    $ButtonName[5] = "lipnote";
    $ButtonName[6] = "sipnote";
    $ButtonName[7] = "rrnote";
    $ButtonName[8] = "rdynote";
    // now let us build our little buttons in a readable fashion
    // start the table cell
    $quicknotes = "<TD colspan = 8 valign=middle align=center bgcolor="#ccffff">";
    // put in our buttons
    for ($counter = 0; $counter < count ($ButtonLabel)+1; $counter++)
    {
    $FixedValueString = parenthesis($ButtonValue[$counter]);
    $quicknotes .= "<FONT size="3" face="Helvetica">$ButtonLabel[$counter]</FONT><INPUT bgcolor = "#ccffff" type = radio name = $ButtonName[$counter] value = "$FixedValueString">";
    }
    // finish our table cell
    print ("$quicknotes</td>");
    print ($border);

    Apologies for my fractured code style, I'm new to this.
    Anyway, my problem is that everything works fine except that I get an extra radio button at the end. I have looked at this everyway, and I cannot figure out why I am getting this extra button.
    Any pointers would be appreciated.
    Thank You,
    dbradford
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    why ($ButtonLabel)+1; count() will count the array properly - so why add the +1?

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    4
    Rep Power
    0
    I had mistakenly left that in, it should not be there. It was one of my attempts to stop the extra button from appearing


    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by firepages:
    why ($ButtonLabel)+1; count() will count the array properly - so why add the +1?
    [/quote]

  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,643
    Rep Power
    4492
    count returns the number of elements, not the last index number of the array.

    $a[0]="0"
    $a[1]="1"
    $a[2]="2"

    count($a) will return 3

    so your for loop should count from 0 to count($buttons) - 1

    hope i'm right... that's what I got from reading some comments from the php manual...

    ---John Holmes
  8. #5
  9. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    .per
    <<for ($counter = 0; $counter < count ($ButtonLabel)+1; $counter++)
    >>


    As Simon said ,remove +1 from that loop.

    it should be

    for ($counter = 0; $counter < count ($ButtonLabel[]); $counter++)

    //it should create 9 buttons for you


    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited July 10, 2000).]
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    4
    Rep Power
    0
    Thank you all, it worked...I should have thought about what count() returns.
    It now prpoerly displays the buttons.
    Now....on to the next problem..

Similar Threads

  1. 9 table join returns extra iteration(s)
    By tinawina in forum PHP Development
    Replies: 2
    Last Post: February 15th, 2004, 07:23 PM
  2. 9 table join returns extra iteration(s)
    By tinawina in forum MySQL Help
    Replies: 0
    Last Post: February 15th, 2004, 07:22 PM
  3. Replies: 11
    Last Post: February 11th, 2004, 01:52 PM
  4. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 06:19 PM
  5. Animations finish inside button?
    By FLASHER in forum Flash Help
    Replies: 4
    Last Post: January 11th, 2004, 12:37 AM

IMN logo majestic logo threadwatch logo seochat tools logo