Hello,
I created a HTML form, with a drop down list of "priority levels". These include 'High', 'Medium', 'Low'. When the user submits the form, it displays the info in a table below the form.
What I want to do is when a user selects a priority level, and fills in the rest of the form, and submits it, it will display the correct priority level image. For example, 'High' priority has a "red" dot. 'Medium' a "yellow" dot, and 'Low' a "blue" dot.
I thought about doing something like this...But don't know to implement that into an HTML drop down form.
PHP Code:
if($priority == 1)
{
echo "<img src='images/high.png' alt='High' title='High'>";
}
elseif($priority == 2)
{
echo "<img src='images/medium.png' alt='Medium' title='Medium'>";
}
elseif($priority == 3)
{
echo "<img src='images/low.png' alt='Low' title='Low'>";
}
Thanks
Here take a look at this code.
PHP Code:
<?php
echo <<<HTML
<form action="index.php" method="post">
<select name="priority">
<option value="1">High
<option value="2">Medium
<option value="3">Low
</select>
<input type="submit" name="submit" value="Submit" />
</from>
HTML;
if(isset($_POST['submit'])) {
$priority = $_POST['priority'];
}else{
die();
}
if($priority == 1)
{
echo "<img src='images/high.png' alt='High' title='High'>";
}
elseif($priority == 2)
{
echo "<img src='images/medium.png' alt='Medium' title='Medium'>";
}
elseif($priority == 3)
{
echo "<img src='images/low.png' alt='Low' title='Low'>";
}
?>
Ok, that worked.
Now all I need is to echo the correct image on each table row. Here is part of my php code...
PHP Code:
<?php
// Important
$id = $row['id'];
$result = mysql_query("SELECT * FROM incidents");
while($row = mysql_fetch_array($result))
{
echo "<input type='hidden' name='id' value='$id'/>";
echo "<tr>";
echo "<td align='middle'>".$row['priority']."</td>";
echo "<td>".$row['type']."</td>";
echo "<td>".$row['location']."</td>";
echo "<td>".$row['details']."</td>";
echo "<td>".$row['rp']."</td>";
echo "<td>".$row['units']."</td>";
echo "<td>".$row['dispo']."</td>";
echo "<td><a href='#'>Edit</a> / <a href='#'>Close</a></td>";
echo "</tr>";
}
?>
Where I have the
PHP Code:
"<td align='middle'>".$row['priority']."</td>";
I need to echo the correct priority image with the following..
PHP Code:
if($priority == 1)
{
echo "<img src='images/high.png' alt='High' title='High'>";
}
elseif($priority == 2)
{
echo "<img src='images/medium.png' alt='Medium' title='Medium'>";
}
elseif($priority == 3)
{
echo "<img src='images/low.png' alt='Low' title='Low'>";
}
You can just put that IF/ELSEIF block on the place of the "$row['priority']" line... but instead of checking $priority, you check $row['priority']
Or a way I would suggest more is, save the images as "priority_1.png" _2/_3....
And then in the $row line you call this.
PHP Code:
echo "<img src=\"images/priority_".$row['priority'].".png\" alt=\"Priority\" title=\"Priority\" />"
(12-30-2009, 12:07 PM)Master of The Universe Wrote: [ -> ]You can just put that IF/ELSEIF block on the place of the "$row['priority']" line... but instead of checking $priority, you check $row['priority']
Or a way I would suggest more is, save the images as "priority_1.png" _2/_3....
And then in the $row line you call this.
PHP Code:
echo "<img src=\"images/priority_".$row['priority'].".png\" alt=\"Priority\" title=\"Priority\" />"
Thank you so much! That worked perfectly
(rep+)
(12-30-2009, 11:21 AM)Dutchcoffee Wrote: [ -> ]Hello,
I created a HTML form, with a drop down list of "priority levels". These include 'High', 'Medium', 'Low'. When the user submits the form, it displays the info in a table below the form.
What I want to do is when a user selects a priority level, and fills in the rest of the form, and submits it, it will display the correct priority level image. For example, 'High' priority has a "red" dot. 'Medium' a "yellow" dot, and 'Low' a "blue" dot.
I thought about doing something like this...But don't know to implement that into an HTML drop down form.
PHP Code:
if($priority == 1)
{
echo "<img src='images/high.png' alt='High' title='High'>";
}
elseif($priority == 2)
{
echo "<img src='images/medium.png' alt='Medium' title='Medium'>";
}
elseif($priority == 3)
{
echo "<img src='images/low.png' alt='Low' title='Low'>";
}
Thanks
Can I make a suggestion, use switch instead of [else]if, just for neater code