Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
nika

Not Works Drop Down Menu

Recommended Posts

i copy everything, only change config and mysql.inc section. i have fixed problem, just add custom css  on bootstrap.min.css like this:

ul li:hover > ul {

display: block;
}

Share this post


Link to post
Share on other sites

I'm not able to get dropdown to function, though I'm following along with the book (and the downloaded code here on the site) and I don't see anything incorrect about my code.   I did try fiddling with the CSS like the original poster, but that attempt wasn't successful (I don't really understand what he did, and the original code should work regardless).

 

On page 73 of the book, when testing...

$_SESSION['user_id'] = 1;

... the "Account" <li> does display, but the dropdown will not function.  Likewise, a check for $_SESSION['user_admin'] has the same result.

 

Otherwise, the layout looks fine.

Share this post


Link to post
Share on other sites

I have it working now.  I found that the downloadable zip from here on Larry's site does not include "bootstrap.min.js" in the project's "js" folder.  (In fact, I just re-downloaded the zip to double check whether it is included, and the file is still missing.)

 

Not sure if I'm missing something glaringly obvious in the code (or something that will be fixed later on), but in any case, I just went to the official Bootstrap site to get the bootstrap.min.js file (as of this date, the default file gets the dropdown up and running).  Not a big problem, but if you're having trouble with this it's just a simple fix.

Share this post


Link to post
Share on other sites

Sorry about the confusion and thanks for sharing that. I assumed people would download and install the most current version of Bootstrap themselves. 

Share this post


Link to post
Share on other sites

I am also encountering some problem with getting my dropdown to work. Infact, it the <li> in the the dropedown under Account is not showing up and my Admin tab is not showing up.

 

As suggested in the above, I have downloaded the bootstrap.min.js file and place it in the js folder and I am following the book instructions as best as I can without any success.  Is there anyway someone can discern where it is am going wrong. Your help would greatly be appreciated.

 

My code in the head.html is as follow:

===================================================================================================

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title><?php // Use a default page title if one wasn\'t'\ provided...
    if (isset($page_title)) {
            echo $page_title;
    } else {
            echo 'C-PARK';
    }
    ?></title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/sticky-footer-navbar.css" rel="stylesheet">

  </head>

  <body>

    <!-- Wrap all page content here -->
    <div id="wrap">

      <!-- Fixed navbar -->
      <div class="navbar navbar-fixed-top">
        <div class="container">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="index.php">CENTENNIAL PARK</a>
          <div class="nav-collapse collapse">
            <ul class="nav navbar-nav">
     <?php // Dynamically create header menus...

// Array of labels and pages (without extensions):
$pages = array (
    'Home' => 'index.php',
    'About' => '#',
    'Contact' => '#',
    'Register' => 'register.php'
);

// The page being viewed:
$this_page = basename($_SERVER['PHP_SELF']);

// Create each menu item:
foreach ($pages as $k => $v) {

    // Start the item:
    echo '<li';

    // Add the class if it's the current page:
    if ($this_page == $v) echo ' class="active"';

    // Complete the item:
    echo '><a href="' . $v . '">' . $k . '</a></li>
    ';

} // End of FOREACH loop.

// Show the user options:
if (isset($_SESSION['user_id'])) {


// Show basic user options:
    // Includes references to some bonus material discussed in Part Four!
    echo '<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Account <b class="caret"></b></a>
        <ul class="dropdown-menu">
            <li><a href="logout.php">Logout</a></li>
            <li><a href="renew.php">Renew</a></li>
            <li><a href="change_password.php">Change Password</a></li>
            <li><a href="favorites.php">Favorites</a></li>
            <li><a href="recommendations.php">Recommendations</a></li>
        </ul>
    </li>';

    // Show admin options, if appropriate:
    if (isset($_SESSION['user_admin'])) {
        echo '<li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin <b class="caret"></b></a>
            <ul class="dropdown-menu">
                <li><a href="add_page.php">Add Page</a></li>
                <li><a href="add_pdf.php">Add PDF</a></li>
                <li><a href="#">Something else here</a></li>
            </ul>
        </li>';        
    }
    
} // user_id not set.

?>
            </ul>
          </div><!--/.nav-collapse -->
        </div><!--/container-->
      </div><!--/navbar-->

      <!-- Begin page content -->
      <div class="container">
    
        <div class="row">
            
            <div class="col-3">
                <h3 class="text-success">Content</h3>
            <div class="list-group">
<?php // Dynamically generate the content links:
$q = 'SELECT * FROM categories ORDER BY category';
$r = mysqli_query($dbc, $q);
while (list($id, $category) = mysqli_fetch_array($r, MYSQLI_NUM)) {
    echo '<a href="category.php?id=' . $id . '" class="list-group-item" title="' . $category . '">' . htmlspecialchars($category) . '
    </a>';
}
?>
             <!-- <a href="pdfs.php" class="list-group-item" title="PDFs">PDF Guides
              </a>-->
              <a href="pdfs.php" class="list-group-item" title="PDFs">Olympum
              </a>
              <a href="pdfs.php" class="list-group-item" title="PDFs">Stadium
              </a>
              <a href="pdfs.php" class="list-group-item" title="PDFs">Chalet
              </a>
              <a href="pdfs.php" class="list-group-item" title="PDFs">Playing Fields
              </a>
              <a href="pdfs.php" class="list-group-item" title="PDFs">Golf
              </a>
              <a href="pdfs.php" class="list-group-item" title="PDFs">Green House
              </a>
              <a href="pdfs.php" class="list-group-item" title="PDFs">Pinic Areas
              </a>
              <a href="pdfs.php" class="list-group-item" title="PDFs">Go Kart
              </a>
              <a href="pdfs.php" class="list-group-item" title="PDFs">Wading Pool
              </a>
            </div><!--/list-group-->

<?php // Should we show the login form?
if (!isset($_SESSION['user_id'])) {
    require('includes/login_form.inc.php');
}
?>
            </div><!--/col-3-->
          
            
          <div class="col-9">
            <!-- CONTENT -->

Share this post


Link to post
Share on other sites

So I was able to solve one of the problem. My Account table is working along with the dropdown menu however, the Admin is not showing up on the menu bar. So if anyone can share a solution I would greatly appreciate it.

cheers.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...