SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member phpandme's Avatar
    Join Date
    Apr 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Form checkboxes "name value" needs to be incremented

    I have a form that dynamically populates the values for checkboxes. My problem exsist when I try to get the name of the checkboxes to increment by one number -- i'm using an array with "$a++ but it's not working.....

    PHP Code:
    $result2 mysql_query("select * from products_description WHERE products_id  = '$products_id'  AND (products_id != $prod1) AND (products_id != $prod2) AND (products_id != $prod3) ORDER BY 'products_ name' ASC") ;



    while(
    $row mysql_fetch_row($result2)) {
    $products_name="$row[2]";
    $num_rows mysql_num_rows($result2);
    echo 
    "<TABLE width=\"300\" cellspacing=\"2\" cellpadding=\"0\" BORDER=\"0\">\n";
    for(
    $i 0$i $num_rows$i++) {
    $row mysql_fetch_array($result);

    if(
    $i%$columns == 0) {
    //if there is no remainder, we want to start a new row
    echo "<TR>\n";
    }
    $a=0;
    do
    {
    $a++;
    echo 
    "<TD width=\"15\">" "<input type=\"checkbox\" name=\"pk_ " $a "\" value=\"$products_id\">" ."</TD><TD>"."<a href=\"show_pack.php?products_id=$products_id\">"."<U><B><font color=\"#4682b4\">" $products_name "</font></B></U>"."</a>"." </TD>\n";
    }
    while (
    $a  count($num_rows));

    if((
    $i%$columns) == ($columns 1) || ($i 1) ==
    $num_rows) {
    //or if there is nothing left in our result set, end the row
    echo "</TR>\n";
    }
    }

    echo 
    "</TABLE>\n";
      }
        } 
    The above form checkboxes also include code to display the checkboxes in coloumns.


    Please help me to get the checkbox names to increment by 1

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $count 3;
    $a 0;

    echo 
    '<tr>';
    for(
    $i=0$i $count$i++)
    {
        
        do
        {
            echo<<<UNIQUEID
                <TD width="15">
                <input type="checkbox" name="pk_ 
    $a" value="something">
                </TD>
                <TD>
                <a href="show_pack.php?products_id=something">
                    <U><B><font color="#4682b4">some text</font></B></U>
                </a>
                </TD>\n
    UNIQUEID;

            
    $a++;

        }while (
    $a $count);

    }
    echo 
    '</tr>'

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,145
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    remainder

    I think you may be a bit confused as to what the modulus "%" operator does.
    This line
    PHP Code:
    if($i%$columns == 0) { 
    says "if the value of the $i var can be divided by the value of the $column var and the result is a whole number"
    ie. if
    $i = 20; // number of rows
    $columns = 5; // number of columns
    then
    $i%$columns = 0
    This is not what you want


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
  •