i just wanna to show 2 color of button with consition status in mysql data if status = 1 , button color = green if status = 2 , button color = red
this is my button code
<?php
$query1 = mysqli_query($connect,"SELECT * FROM smt WHERE no <= 15");
while ( $data=mysqli_fetch_array($query1)){
$nostation = $data['no'];
$namastation = $data['name'];
$status = $data['status'];
?>
<div class='col-xs-2-2'>
<form method='post'>
<input type="hidden" value="2" id="status_<?=$nostation;?>" name="status">
<button type="submit" id="button_<?=$nostation;?>" data-id="<?=$nostation;?>" style="width:140px; height:75px; margin : 2px; border-radius:10%;"><b style="font-size:15px; color: #fff; font-family:Calibri;"><?php echo $namastation ?></b></button>
</form>
</div>
<?php } ?>
and this is my color code with js, now i just can set color to all button no condition with value of status. anyone can help me ?
<script type="text/javascript">
$(document).ready(function(){
$("[id^=button_]").css("background-color", "Red");
});
</script>
and i this is my ajax code to set multiple button with autogenerate id
<script>
$(document).ready(function(){ //when DOM is Ready.
$("[id^=button_]").click(function () { //when Button is Clicked.
var id = $(this).data('id'); // Get the ID of the button that was clicked on.
var status = $("#status_"+id).val(); // value from `input` which is connected the clicked button.
// console.log(id+"---"+name);
$.ajax({ // AJAX request
url: 'coba1.php', // send request to server.
method: 'POST', // method is POST.
data: { //data which is sent to server.
id: id,status: status
},
function (data) { //success function called.
// alert success data.
}
});
});
});
how i add the code to set button color with condition ?