Hey guys please help me with my code, I want to disable select drop down if $stat=a, this is my code. Thank You!

echo "<select name='name' id='name' 'if ($stat =='a'){ echo ('disabled');}'>";

Recommended Answers

All 9 Replies

echo "<select name='name' id='name' <?php if ($stat =='a'){ echo ('disabled');} ?> >";

I haven't actually tested that but the main point is you need the <?php ?> tags otherwise you're just going to echo out the if statement as text.

still the same :(

$disabled = $stat =='a' ? 'disabled' : '';
echo "<select name='name' id='name' $disabled>";

Gotcha, thank you... Can you please explain the 1st line of the code. Thank You!

if i may revised the code a bit, i think the second line code should be like this:

echo "<select name='name' id='name' ".$disabled.">";
Member Avatar for diafol

No fang. Simple Variables can be parsed within double quotes. There is no need to concatenate them.

i'll never write the code that way, i thought it will be read as string.
I'll try it. thank you

Thank You Guys for your help :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.