How To Disable Button Based On Database?
Solution 1:
1 method is that you can populate the table in Php by echoing the Table in HTML.
Another method would be to use a for loop in ur html looping through your data and do an if else in the loop to check the existence of the username. If true, use this set of button codes, if false, use this set of button codes.
Solution 2:
The code snippet is a little bit out of context, so it's hard to know if this is possible, but assuming your PHP and HTML are part of the same script file (or least the one with the HTML includes/requires the one with the database code), then you can do something simple like this:
<?php$user_check_query = "SELECT * FROM paym WHERE username = '" . $_SESSION['username'] . "' ";
$result = mysqli_query($db, $user_check_query);
$showButton = (mysqli_num_rows ($result) > 0 ? true : false);
?>
...
<?phpif ($showButton == true) {
?><inputclass="reload-but"type="button"value="↻""><?php
}
?>
This will cause PHP to only send the button HTML to the browser when the if
condition is true.
Solution 3:
echo "<input class=\"reload-but\" type=\"button\" value=\"↻\"".(count($row) >0?" disabled" : " ".">";
Or, as @Justinas said, you can just echo the button only when you have a positive result.
Post a Comment for "How To Disable Button Based On Database?"