Click here to Skip to main content
15,028,681 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Unable to get dropdown items from database



<title>Bootstrap Example
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">











MYSQL PHPMYADMIN
CREATE TABLE `menu` (
`m_id` int(11) NOT NULL,
`m_name` varchar(50) NOT NULL,
`m_url` varchar(100) NOT NULL,
`m_desc` varchar(255) NOT NULL,
`m_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)

--
-- Table `menu`
--

INSERT INTO `menu` (`m_id`, `m_name`, `m_url`,`m_created`) VALUES
(1, 'Home', '', '2018-05-03 06:20:17'),
(2, 'Page 1', '', '2018-05-03 11:05:46'),
(3, 'Page 2', '', '2018-05-03 11:06:03')
(4, 'Page 3', '', '2018-05-03 11:06:03');



CREATE TABLE `menu_item` (
`m_item_id` int(11) NOT NULL,
`m_id` int(11) NOT NULL,
`m_item_name` varchar(50) NOT NULL,
`m_item_url` varchar(100) NOT NULL,

`m_item_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Table `menu_item`
--

INSERT INTO `menu_item` (`m_item_id`, `m_id`, `m_item_name`, `m_item_url`, `m_item_desc`, `m_item_created`) VALUES
(1, 2, 'Web Icons', '', '2018-05-03 11:07:07'),
(2, 2, 'Typography', '', '2018-05-03 11:07:31');

What I have tried:

<?php
include("config.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">WebSiteName</a>
    </div>
    <ul class="nav navbar-nav">

<?php
$sql_menu="select * from menu";
$result_menu = $conn->query($sql_menu);
if ($result_menu->num_rows > 0) {
while($row_menu = $result_menu->fetch_array()) { ?>
<li><a href="#" ><?php echo $row_menu['m_name']; ?></a></li>
<?php } }?>
</ul>

      <!--<li class="active"><a href="#">Home</a></li>
      <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a href="#">Page A</a></li>
          <li><a href="#">Page B</a></li>
          <li><a href="#">Page C</a></li>
        </ul>
      </li>
      <li><a href="#">Page 2</a></li>
      <li><a href="#">Page 3</a></li>-->
    </ul>
  </div>
</nav>
  


</body>
</html>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900