0

I want to select and display the Column Name of my table. I used SHOW SQL Command to display the data to my select box. The problem is I want to omit Two(2) columns, ID and Image column to be exact. I have no problem with displaying all the column names. Please refer to my code below for more details.

PHP Code:

<?php 
    require "connect.php";

    $sql = "SHOW columns FROM tblLocation";
    $result = mysqli_query($conn,$sql);

    while ($row = mysqli_fetch_array($result)) {
        echo "<option value='".$row['Field']."'>".ucfirst($row['Field'])."</option>";
    }
?>
4
  • column to be exact Not Understand Commented Feb 13, 2018 at 5:57
  • how can i skip it? Commented Feb 13, 2018 at 5:57
  • @TarangP "to be exact" is an idiom meaning "specifically". Those are the two columns he wants to omit. Commented Feb 13, 2018 at 5:58
  • make a array of the columns you want to show, compare it and show only matched Commented Feb 13, 2018 at 5:58

1 Answer 1

1

use an if statement:

if ($row['Field'] != 'ID' && $row['Field'] != 'Image') {
    echo "<option value='".$row['Field']."'>".ucfirst($row['Field'])."</option>";
}
Sign up to request clarification or add additional context in comments.

2 Comments

I worked, I just have one more question. How can I omit Two columns if i do not know what is the name of that column?
If you don't know their names, what criteria do you want to use to omit them?

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.