-1

I created button like this:

<button type = "submit" name="one" class="button button1">B-1</button>

It makes table value 1 from 0 after a click. But button color remains same. Now I want to change the button color with change of table value. #TIA

I_love_vegetables
  • 1,575
  • 5
  • 12
  • 26

1 Answers1

0

When you get your data from your database you can add a class to each button based on the field value, and create a CSS class that styles that button.

For example, let's say your B-1 button with the name 'one' changes the field checked with the name same as the button's name in your table.

name checked
one 1
two 0

When you load your page and query the table with PHP (e.g. mysqli_query("select checked from my_table where name='one'")) and fetch the data, you can do the following:

<button type="submit" name="one" class="button button1 checked-<?php echo $query_result['checked']; ?>">B-1</button>

Assuming you have stored your query result in $query_result, checked should either be 1 or 0, therefore adding a class with the name checked-0 or checked-1.

Then, in your CSS file or <style> tag add two classes:

.checked-0{color:red;}
.checked-1{color:green;}
nbk
  • 45,398
  • 8
  • 30
  • 47
tugrul
  • 135
  • 3