I have 5 columns in database id, a1, b1, c1 and d1. I want to show button a if the value in database for a1 is not there and if two values eg. c1 and b1 is present in database i want to show buttons for a and d.
Simple thing I want to show the button for that if there is no value in database.
I have tried the it by entering 16 conditions but it take a lot of time and space.
if(($row['a1'] == '') && ($row['b1'] != '') && ($row['c1'] != '') && ($row['d1'] != '')) { ?> <form action = "a1.php" method="POST"> <input type="submit" name="a1" value="a1"> </form> <?php } elseif (($row['b1'] == '') && ($row['a1'] != '') && ($row['c1'] != '') && ($row['d1'] != '')) { ?> <form action = "b1.php" method="POST"> <input type="submit" name="b1" value="b1"> </form> <?php } elseif (($row['c1'] == '') && ($row['a1'] != '') && ($row['d1'] != '') && ($row['b1'] != '')) { ?> <form action = "c1.php" method="POST"> <input type="submit" name="c1" value="c1"> </form> <?php } elseif (($row['d1'] == '') && ($row['a1'] != '') && ($row['b1'] != '') && ($row['c1'] != '')) { ?> <form action = "d1.php" method="POST"> <input type="submit" name="d1" value="d1"> </form> <?php } ?>
Is there any other way to do this.
Thanks in advance
Advertisement
Answer
here is the logic you can try.if you are going for specific row
step1: select the row according to id
$sql = SELECT * FROM Customers WHERE id=xyx(your preferred id);
step2: fetch a assosiative array.
$result=mysqli_query($con,$sql); // Associative array $row=mysqli_fetch_assoc($result);
step2: check for the condition.
if(isset($row['a1'])){ echo "<button></button>" }