SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    urgent help required in php coding to display checkboxes in 5/5 format

    hi there im a newbie and new to this forum and need the help from this community to solve my issue i have a function which displays checkboxes but it is not formatted properly it is come one by one and grouped together
    plz help me with the proper logic code to arrange the list of checkboxes in 5/5 format my current code which is not displaying the layout of the checkboxes properly is :

    function checkBoxList( &$arr, $tag_name, $tag_attribs, $selected=null, $key='value', $text='text', $porlinea=false )
    {
    reset( $arr );
    $html = "";
    for ($i=0, $n=count( $arr ); $i < $n; $i++ ) {

    $k = $arr[$i]->$key;
    $t = $arr[$i]->$text;
    $id = @$arr[$i]->id;

    plz reply me with the proper logic code to display these checkboxes in a proper format of 5/5

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    When every fifth checkbox occurs, you can use the &#37; operator to add extra code to add a break to the list of checkboxes.

    for example:

    Code php:
    for (...) {
        ...
        if ($i > 0 && $i % 5 === 0) {
            echo '<br>';
        }
    }

    This works because 5 % 5 = 0, and 6 % 5 = 1, so when %i is a multiple of 5, $i % 5 will equal 0, letting you know that it's the right time to add another break.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot RishikeshJha's Avatar
    Join Date
    Mar 2009
    Location
    INDIA
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    put if condition in for loop that checks the no of checkbox to display in a row.

    if($i !=0 && $i &#37; 5==0){

    }

    Above code will check for five checkbox to display in a row.


Tags for this Thread

Bookmarks

Posting Permissions

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