Note that there are some explanatory texts on larger screens.

plurals
  1. POphp mysql echo | How to inherit colors from a submit form?
    primarykey
    data
    text
    <p>I'm having some real trouble finding information on this topic and I would be very appreciative for any help. In short I have a form where users select a category from a drop down list, enter some contents, and hit submit which goes to SQL. Each category in the dropdown is color coded:</p> <pre><code>&lt;option STYLE="color: #00CC66;" value="Option_1"&gt;Option_1&lt;/option&gt; &lt;option STYLE="color: #0066CC;" value="Option_2"&gt;Option_2&lt;/option&gt; &lt;option STYLE="color: #996633;" value="Option_3"&gt;Option_3&lt;/option&gt; </code></pre> <p>etc</p> <p>Then I have a php that pulls up the stored submitted data (categories and contents) into a table on that same page sorted by date.</p> <pre><code>&lt;?php $con=mysqli_connect("localhost","myuser","mypassword","mydb"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM mytable order by date DESC"); echo "&lt;table border='1'&gt; &lt;tr&gt; &lt;th&gt;Category&lt;/th&gt; &lt;th&gt;Contents&lt;/th&gt; &lt;th&gt;Date/Time&lt;/th&gt; &lt;/tr&gt;"; while($row = mysqli_fetch_array($result)) { echo "&lt;tr&gt;"; echo "&lt;td&gt;" . $row['category'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['contents'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['date'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; mysqli_close($con); ?&gt; </code></pre> <p>My question is, when echo places the information in the table, is there a way I can get 'category' showing up in the same colors as the user form? (IE, on the table, Option_1 would show up as #00CC66, Option 2 as 0066CC, etc...)</p> <p>Basically I want the actual category text on the fetched table to display the same as it is in the drop down form. I don't mind if I need to manually set each one as the categories are limited, I just have no clue where to begin on this one. Appreciate any help in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload