Jump to content

[SOLVED] HTML within PHP - Help needed


vozzek

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/70504-solved-html-within-php-help-needed/
Share on other sites

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";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.