vozzek Posted September 24, 2007 Share Posted September 24, 2007 Hi everyone, Forgive my newbie PHP skills, but I'm trying to learn. I've got a recordset on my detail page that can hold up to 5 possible colors for an item. For example, let's say Color1=blue, Color2=red, Color3=white. Color4 and Color5 are null values. I obviously only want to populate the Available Colors listbox with non-null values. I'm having trouble with my php code, and was hoping someone could tell me why it doesn't work: <form id="form1" name="form1" method="post" action=""> <label>Available Colors <select name="Colors" id="Colors"> <?php if (strlen($row_rs_assoc_colors['color1'])>0) { <option>'$row_rs_assoc_colors['color1']'</option> } ?> </select> </label> </form> Can I execute php within the html I have above? Or is there a better way to do this? Additionally, I'd like to show the Available Colors drop-down list ONLY if an item has Color1 populated in the assoc_colors table. Meaning that sometimes an item won't come in any colors at all, and therefore I don't need to see the listbox. But I guess that's another question... Thanks in advance for any help! -Vozzek Quote Link to comment https://forums.phpfreaks.com/topic/70504-solved-html-within-php-help-needed/ Share on other sites More sharing options...
darkfreaks Posted September 24, 2007 Share Posted September 24, 2007 you would have to rearrange it abit i think you cant execute html inside of the php tags. unless you echo or print it out Quote Link to comment https://forums.phpfreaks.com/topic/70504-solved-html-within-php-help-needed/#findComment-354158 Share on other sites More sharing options...
vozzek Posted September 24, 2007 Author Share Posted September 24, 2007 Cool, can you please show me an example of how I'd echo it? Quote Link to comment https://forums.phpfreaks.com/topic/70504-solved-html-within-php-help-needed/#findComment-354159 Share on other sites More sharing options...
pocobueno1388 Posted September 24, 2007 Share Posted September 24, 2007 Give this a try <?php if (!empty($row_rs_assoc_colors['color1'])){ ?> <form id="form1" name="form1" method="post" action=""> <label>Available Colors <select name="Colors" id="Colors"> <?php if (!empty($row_rs_assoc_colors['color1'])) { echo "<option>{$row_rs_assoc_colors['color1']}</option>"; } ?> </select> </label> </form> <?php } else { echo "No colors to choose"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70504-solved-html-within-php-help-needed/#findComment-354161 Share on other sites More sharing options...
vozzek Posted September 24, 2007 Author Share Posted September 24, 2007 pocobueno, you rock! Thanks. It was just what I needed, and I understand why it works. Thanks again everyone. Quote Link to comment https://forums.phpfreaks.com/topic/70504-solved-html-within-php-help-needed/#findComment-354165 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.