Re: using for loop in function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Kurth wrote:
   The function below will create a group of checkboxes it will also check
the checkbox that is stored in the table field that is in $select_value this
works fine if there is only one value in the variable but if there is more
stored like 1,2,3,4 it will not work. I am trying to figure out how to use
the following for loop to add the number to each checkbox and if they match
mark the checkbox checked
$ExplodeIt = explode(",",$select_value,",");
        $Count = count($ExplodeIt);
        for ($i=0; $i < $Count; $i++) {
          }



function checkbox($sqlu,$name,$value1,$value2,$select_value){
      $name_result = safe_query($sqlu);
       while($rowu=mysql_fetch_array($name_result)){
  echo "<tr><td colspan=\"2\" align=\"left\"><input type='checkbox' name='"
. $name . "[" . $rowu[$value1] . "]' value=\"$rowu[$value1]\"";

Pass in an array to this function and then do:

if (in_array($rowu[$value1], $selected_items)) {
  echo " CHECKED";
}

echo rest of stuff....

or get the function to handle one item or multiple:

if (!is_array($select_value)) {
  $select_value = array($select_value);
}


If that doesn't work then what are you passing in (ie what is $select_value) and what is in the data (print_r($rowu)) ?

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux