0

In the website, I am trying to make (for educational and personal purposes only) I have a SQL table which I am trying to inject data into. On this PHP page, I have added the ability to create tables ' a competition ' and I want to be able to list all created tables on an option list, however, I cannot work out how to display each competition created separately on their own line.

There are many partial solutions already out there on StackOverflow and the 'wide web' but I cannot seem to find a solution for a drop down option list in HTML

<button class = button type="submit" form="Update" value="create climbs" onclick="onButtonClick() ">Add New climb</button>
                <p></p>
                <form method = "post" action="admin.php">

                <input class = "hide" type="text" name = "climbname" id="climbname" placeholder= "Climb Name" />    

                 <select class = "hide" type="text" name = "comp" id="competiton" placeholder= "Which comp">
                    <option value="2019axis">2019AXIS</option>
                    <option value="2019annual">
                    <?php 
                    $db = mysqli_connect("localhost", "root", "", "authentication");
                    $result = mysqli_query($db,"show tables"); 
                    while($table = mysqli_fetch_array($result)) { 
                    echo($table[0]."<br>" );  } ?>
                    </option>
                 </select>

As shown in the screenshot http://prntscr.com/mddlbg, all competitions are listed together on one line. However, I only want the first 2 tables shown in the SQL database http://prntscr.com/mddlo7.

I understand this may be a very easy solution, however, any help is greatly appreciated.

2
  • Do you want those result as each option or only first 2 tables ? Commented Jan 28, 2019 at 18:19
  • I want it to show only the competition tables but showing the first 2 tables from the authentication database would be enough for me. Just not the user's table basically, ignore the '2019AXIS' all caps options since this was manually put in. Commented Jan 28, 2019 at 18:37

1 Answer 1

2

you have to add inside the loop to create separate options for each table like,

<select class = "hide" type="text" name = "comp" id="competiton" placeholder= "Which comp">
    <option value="2019axis">2019AXIS</option>

    <?php 
          $db = mysqli_connect("localhost", "root", "", "authentication");
          $result = mysqli_query($db,"show tables"); 
          while($table = mysqli_fetch_array($result)) {           
              echo '<option value="'.$table[0].'">'.$table[0].'</option>';  
          } 
    ?>
</select>
Sign up to request clarification or add additional context in comments.

Comments

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.