getting default value for radio button from query [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

getting default value for radio button from query [SOLVED]

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You're using the assignment operator. (=) You need to use the comparison operator. (==)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

default radio value question [solved]

Post 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.
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

Post by lafflin »

wait, there is no !==, that would be != I think.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: default radio value question [solved]

Post 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!
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

Post by lafflin »

It's possible t be equal but of different data types? med int and tiny int or text..etc?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply