Leo
Leo

Reputation: 37

Using bootstrap drop down button, getting options from database

EDIT

So thank you to everyone so far, you have all been amazing. I found out that even though I had THOUGHT I loaded all the proper bootstrap code I apparently, did not... SO as it stands now all seems to be working! Thank you again, all so much. It was simply a combo of cluttered code and lack of proper bootstrap enabling.

I tried to look but did not find anything to resolve this issue. I am using Bootstrap for a drop down button that I am trying to populate the options in the drop down from my database. The database itself is working fine, I am able to get the data from the database itself, but I am seeming to be stuck on just making the options appear/work in the actual button itself.

Here is the button code.

      <div class="btn-group">
        <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Select Weapon <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
        <?php 
          //Check if at least one row is found
            if($result->num_rows >0){
                //Loop through results
                while($row = $result->fetch_assoc()){
                  //Display customer info
                  $output ='<li>';
                  $output .='<li>'.$row['weapon_name'].'</li>';
                  $output .='</li>';

                  //Echo output
                  echo $output;
                  }
                }
            ?>
        </ul>
      </div>

Here is a link to an image of what is showing up from the code above. (I am not able to post direct images quite yet.) Button image

Any ideas? Thank you in advanced!

Upvotes: 2

Views: 2001

Answers (4)

Leo
Leo

Reputation: 37

Utilizing the re-affirmed bootstrap code that seemed to have, while clearing my css stuff (minor), fixed the button to work and properly show the database. Thank you all.

Upvotes: 0

Mammu yedukondalu
Mammu yedukondalu

Reputation: 156

$output ='<li>'; //// Remove this line
$output .='<li>'.$row['weapon_name'].'</li>';
$output .='</li>'; //remove this line also
//Echo output
echo $output;

Hope it will work .

Upvotes: 0

TigerBoy343
TigerBoy343

Reputation: 1

I think this may help you:

while($row = $result->fetch_assoc()) {

//Display customer info
    $output = $row['weapon_name'];
    echo '<li>'.$output.'</li>';
    //Echo output in list

}

keep other code as it was.

Upvotes: 0

neophyte
neophyte

Reputation: 6624

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
          <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
           <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
           <style type="text/css">
        
           </style>
           
           </head>
           <body>
           <div class="btn-group dropdown">
        <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Select Weapon <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
        <li>Q</li>
      <li>N</li>
      <li>V</li>
      <li>A</li> 
      <li>O</li>
      </ul>
      </div>

           </body>
           </html>
           

Try this---

just remove these $output ='<ul>'; $output .='</ul>'; lines.

<div class="btn-group">
        <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Select Weapon <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
        <?php 
          //Check if at least one row is found
            if($result->num_rows >0){
                //Loop through results
                while($row = $result->fetch_assoc()){
                  //Display customer info
                 echo '<li>';
                 echo($row['weapon_name']);
                 echo'</li>';


                  //Echo output
                  echo $output;
                  }
                }
            ?>
        </ul>
      </div>

Hope this helps!

Upvotes: 1

Related Questions