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.
JavaScript
x
27
27
1
if(($row['a1'] == '') && ($row['b1'] != '') && ($row['c1'] != '') && ($row['d1'] != '')) {
2
?>
3
<form action = "a1.php" method="POST">
4
<input type="submit" name="a1" value="a1">
5
</form>
6
<?php
7
} elseif (($row['b1'] == '') && ($row['a1'] != '') && ($row['c1'] != '') && ($row['d1'] != '')) {
8
?>
9
<form action = "b1.php" method="POST">
10
<input type="submit" name="b1" value="b1">
11
</form>
12
<?php
13
} elseif (($row['c1'] == '') && ($row['a1'] != '') && ($row['d1'] != '') && ($row['b1'] != '')) {
14
?>
15
<form action = "c1.php" method="POST">
16
<input type="submit" name="c1" value="c1">
17
</form>
18
<?php
19
} elseif (($row['d1'] == '') && ($row['a1'] != '') && ($row['b1'] != '') && ($row['c1'] != '')) {
20
?>
21
<form action = "d1.php" method="POST">
22
<input type="submit" name="d1" value="d1">
23
</form>
24
<?php
25
}
26
?>
27
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
JavaScript
1
2
1
$sql = SELECT * FROM Customers WHERE id=xyx(your preferred id);
2
step2: fetch a assosiative array.
JavaScript
1
5
1
$result=mysqli_query($con,$sql);
2
3
// Associative array
4
$row=mysqli_fetch_assoc($result);
5
step2: check for the condition.
JavaScript
1
4
1
if(isset($row['a1'])){
2
echo "<button></button>"
3
}
4