-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

2
  • <button type = "submit" name="one" class="button button1">B-1</button> Commented Aug 22, 2021 at 21:38
  • Does this answer your question? Change CSS value by using PHP Commented Aug 24, 2021 at 6:46

1 Answer 1

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;}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.