I need to disable or hide, button if existsusername
in the table, and ==
logged in user
For example: username John
exists in table paym
we should disable button to John
table: paym
ID username column1 column2
+-------+-------------+-------------+-----------+
| 1 | John | Value | Value |
+-------+-------------+-------------+-----------+
| 2 | Alex | Null | Null |
+-------+-------------+-------------+-----------+
Only infrmation that I can provide you:((
This is button in Html:
<input class="reload-but" type="button" value="↻"">
** logic behind similar to this php code:**
<?php
$user_check_query = "SELECT * FROM paym
WHERE username = '" . $_SESSION['username'] . "' ";
$result = mysqli_query($db, $user_check_query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
?>
Who can do fully workable code, with explained code!
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.
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.
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);
?>
...
<?php
if ($showButton == true) {
?>
<input class="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.