Page 1 of 1

getting default value for radio button from query [SOLVED]

Posted: Sat Sep 15, 2007 9:58 am
by lafflin
hello, I am trying to get the default value selected in a set of two radio buttons from my query results, I would have expected the following to work:

Code: Select all

echo ' <td>
			 <label>
              <input type="radio" name="sex" ' ;
			   if ($row['sex'] = 'f') {echo 'checked ="checked" '  ;} 
			    echo 'value="f" />
              Female</label>
            <br />
            <label>
              <input type="radio" name="sex" ' ;
			  if ($row['sex'] = 'm') {echo 'checked ="checked" '  ;}
			   echo 'value="m" />
              Male</label>
			 </td>'
The data type for sex is enum, with 'm' or 'f' as possible values.

the html I am getting from this code has both radio buttons set as "checked".


any help is apprectiated.

Posted: Sat Sep 15, 2007 12:36 pm
by s.dot
You're using the assignment operator. (=) You need to use the comparison operator. (==)

default radio value question [solved]

Posted: Sat Sep 15, 2007 1:04 pm
by lafflin
Yep, I just seen that and was comming back to answer my own question.

answer:

(=) !== (==)

scott you seem to be everywhere lately, and very willing to help with very straightforward answers, us newbs appreciate that.

Posted: Sat Sep 15, 2007 1:05 pm
by lafflin
wait, there is no !==, that would be != I think.

Re: default radio value question [solved]

Posted: Sat Sep 15, 2007 1:06 pm
by s.dot
lafflin wrote:scott you seem to be everywhere lately, and very willing to help with very straightforward answers, us newbs appreciate that.
Glad to help, and compliments are always appreciated. ;) Thanks!

Posted: Sat Sep 15, 2007 1:11 pm
by s.dot
lafflin wrote:wait, there is no !==, that would be != I think.
There is a !== and a !=

!= checks that they're note equal, regardless of type
!== checks that they're equal and that they're of the same type (string, integer, etc)

Posted: Sun Sep 16, 2007 12:57 am
by lafflin
It's possible t be equal but of different data types? med int and tiny int or text..etc?

Posted: Sun Sep 16, 2007 1:32 am
by s.dot
lafflin wrote:It's possible t be equal but of different data types? med int and tiny int or text..etc?
Yes, ==.

'5' == 5 (string and integer)