jimitodd Posted January 1, 2014 Share Posted January 1, 2014 (edited) 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. Thanks 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 January 1, 2014 by jimitodd Link to comment Share on other sites More sharing options...
niche Posted January 1, 2014 Share Posted January 1, 2014 Use an if statement http://www.w3schools.com/php/php_if_else.asp Link to comment Share on other sites More sharing options...
jimitodd Posted January 2, 2014 Author Share Posted January 2, 2014 Thanks I've tried these two options but both give syntax errors. first on the if and style lines. second on the if line first <?php$st=(echo $rows['status']);if ($st="On Time") { style="color:green"; }elseif ($st="Delayed") { style="color:orange"; }elseif ($st="Cancelled") { style="color:red"; }?> second.. <?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 More sharing options...
Ingolme Posted January 3, 2014 Share Posted January 3, 2014 It seems you need to read the PHP tutorial thoroughly before continuing. http://w3schools.com/php/php_intro.asp You need to understand the PHP syntax and the difference between PHP and HTML. Link to comment Share on other sites More sharing options...
jimitodd Posted January 3, 2014 Author Share Posted January 3, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now