Jump to content

Conditional Formatting


Recommended Posts

I have an update form uploading to mysql and a php/html page downloading to a table on another page.


What I would like is the website to colour code the status on the public page depending on the input form.

I've tried alsorts of code on the form, the results and a stylesheet.


Any help or suggestions welcome.




Here's the relevant bit of the form code.


<select name="status" type="text" id="status" value="<? echo $rows['status']; ?>"> <option style= "color:green" value="On Time">On Time</option> <option style= "color:orange" value="Delayed">Delayed</option> <option style= "color:red" value="Cancelled">Cancelled</option> </select>


and this is the cell from the page.


<td>Status</td><td><?php echo $rows['status']; ?></td>

Edited by jimitodd
Link to comment
Share on other sites

Thanks I've tried these two options but both give syntax errors.

first on the if and style lines.

second on the if line




<?php$st=(echo $rows['status']);if ($st="On Time") { style="color:green"; }elseif ($st="Delayed") { style="color:orange"; }elseif ($st="Cancelled") { style="color:red"; }?>




<?phpecho $rows['status'];if (['status']="On Time") { style="color:green"; }elseif (['status']="Delayed") { style="color:orange"; }elseif (['status']="Cancelled") { style="color:red"; } else { style="color:black"; }?>

Link to comment
Share on other sites

Got there eventually.

I think I was trying to over complicate it, I had a day off and came back with a fresh pair of eyes.


<?phpif ($rows['status'] == "On Time") {echo '<font color="green">On Time</font>';} elseif ($rows['status'] == "Delayed") {echo '<font color="orange">Delayed</font>';} else {echo '<font color="red">Cancelled</font>';} ?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...