Chris, Good idea, but $default is the value with pipe delimiters. on 12/7/04 4:11 PM, Christopher Fulton at christopher.fulton@xxxxxxxxx wrote: > A few notes that may help you..... > > first.....on strstr....i would use strpos instead for a simple check....so.... >> if(strstr($default, $values[$i]['id'])) { >> $field .= ' CHECKED'; >> } > would become.... >> if(strpos($default, $values[$i]['id']) !== false) { >> $field .= ' CHECKED'; >> } > note the double equals...not a mistake....see note in php docs about > that...the reason for using strpos is that strstr is a much longer > check than needed.....anyways...on to your problem..... > > there is a slight logic issue (i think....) > lets say your values are.... > $values = "foo bar|foo"; > this test (i think) should return true.... > if(strstr("foo", $values)) because it just looks for the first > occurence of the string.... > > > to fix this..... > > I would change it to this..... > $checkValues = array() > $checkValues = explode("|", $values[$i]['id']); > if(in_array($default, $checkValues)) { > $field .= ' CHECKED'; > } > > there may be a better/faster way to do this, but this should work > > hope this helps, > chris > > > > On Tue, 07 Dec 2004 15:10:59 -0500, Mike <mike@xxxxxxxxxxxx> wrote: >> >> >> Hello, >> >> I am having a hard time figuring this one out, maybe someone here (with >> fresh eyes) can offer a suggestion? >> >> Here is the function... >> >> // Draw Checkbox Menu >> function draw_checkbox_menu($name, $values, $default = false, $parameters = >> false) { >> >> for ($i=0; $i<sizeof($values); $i++) { >> $field .= '<input type="checkbox" name="'.$name.'" value="' . >> $values[$i]['id'] . '"'; >> if(strstr($default, $values[$i]['id'])) { >> $field .= ' CHECKED'; >> } >> $field .= '> ' . $values[$i]['text'] . '<br> >> '; >> } >> >> return $field; >> } >> >> This function is passed the name of the checkbox list($name), the values >> that are available($values = array) along with the ones that should be >> checked ($default). Parameters too , but not important. >> >> The problem is this. The Values are formatted like this... >> >> value1|value2|value3...etc... >> >> I use the strstr() function to check against the $default so I can check it >> if so. >> >> Well it works great..BUT, lets say the product has a category of "Coffee >> Pots", but the one of the values available is "Coffee". >> >> In this case both "Coffee" AND "Coffee Pots" get checked when only "Coffee >> Pots" should. >> >> What can I do to this function eliminate this? >> >> Thanks >> >> +--------------------------------------------+ >> Mike Yrabedra >> Mac@xxxxxxxx >> Your Mac Intelligence Resource >> +--------------------------------------------+ >> W: http://www.macagent.com/ >> E: agenty@xxxxxxxxxxxx >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> +--------------------------------------------+ Mike Yrabedra Mac@xxxxxxxx Your Mac Intelligence Resource +--------------------------------------------+ W: http://www.macagent.com/ E: agenty@xxxxxxxxxxxx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php