Jump to content

How to query a value from mySQL that will change a <tr> background color


FoxRocks

Recommended Posts

Hello,

 

Thank you for your interest in my problem. I have an input form for a mySQL db and then another form that displays the stored data. That part I got figured out (I'm still very new to PHP and mySQL) but this second part I am not sure how to attack.

 

What I have is 21 records containing aircraft schedules. The aircraft column in the db never changes, they are pre populated with the aircraft id. Then there are two other columns that do change depending on the schedule and date. So I made my db so it only updates the current records.

 

What I want to do is have another option that will change the <tr> background color of a certain row depending on a radio button selection. I've got three radio buttons for each aircraft, one for "AOG" one for "Offline" and one for "Online".  I want the user to be able to select the status of the aircraft by using these radio buttons, and as a result, have the display form pull that status from the db and display the <tr> color accordingly.

 

How I picture this working is by having the radio button enter a "true or false" statement into the db by either a "1 or 0" and then on the other end the display form would query the column, and through an if/else statement, select the <tr> color to use.

 

I've got to be honest, even after typing that I'm confused and can't quite get my head around it. I really want to learn this myself so for right now I would really appreciate just a rough direction to take and to let me know if I'm on the right track or not.

 

Also, please let me know if you need more info and I apologize in advance if I didn't make any sense :)

 

Cheers,

 

~FOX~

Link to comment
Share on other sites

Hi Barand,

 

Thanks for the reply, I was actually working on this to try and find a solution for myself before turning to outside help...and I'm feeling really good about myself right now because I was able to get it figured out. I had to look to see how to echo the status back to the radio button, but other than that I got it to work. So happy :)

 

Not sure, but just in case someone else finds this thread looking for an answer, here is the just of what I did:

 

Form:

 

<form action="update.php">
<input type="radio" name="ABC_Status" value="aog" <?php if ($Status['aircraft_status'] == 'aog') {echo "checked";} ?>></input>

 

update.php:

 

$Status = $_POST['ABC_Status'];

 

UPDATE db:

 

mysql_query("UPDATE database_name SET aircraft_status='$Status' WHERE aircraft_reg='ABC'");

 

FETCH from db:

 

$result = mysql_query("SELECT aircraft_status FROM database_name WHERE aircraft_reg='ABC'", $connection);
$Status = mysql_fetch_array($result);

 

Then on the display table I did this:

 

CSS:

tr.aog {background-color:#FF0000;}
tr.offline {background-color:#FFFF00;}
tr.online {background-color:none;}

Table:

<table>

<tr class="<?php echo($Status['status']); ?>">
<td></td>
</tr>

</table>

 

I think that covers it. I know I've searched a hundred times looking for an answer, only to find that when the poster got it figured out they simply said "Yep! I figured it out." but didn't say how, so hopefully this helps someone.

 

Cheers,

~FOX~

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.