0

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

3
  • 3
    please share the code what you've tried so far Commented Feb 27, 2017 at 6:09
  • I have applied the conditions like this Commented Feb 27, 2017 at 6:22
  • Does your code work as expected? Commented Feb 27, 2017 at 6:46

2 Answers 2

3

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>"
   }
Sign up to request clarification or add additional context in comments.

Comments

-1

echo "<button I'd=btn onClick=function()>call function Doesn't work to call javascript function

1 Comment

Hi Alex, welcome to StackOverflow! Could you please elaborate your given answer? It's really short at the moment, and doesn't actually seems to be a good 'answer'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.