Jump to content
Larry Ullman's Book Forums

Jacques

Members
  • Content Count

    48
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Jacques

  • Rank
    Member
  1. Hi Larry, I updated the code to the snippet below but it still gives me an "Undefined offset" error for values 2 onward. I had a look inside a number of your books that I have but can't find my mistake. Any further comment to guide me will be appreciated. Thank you and regards. ... <div class="mega-dropdown-menu row row-no-padding">'; // Retrieve all the languages and add to the pull-down menu: $q = "SELECT id, lang FROM languages WHERE status='Active' ORDER BY lang ASC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo '<div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[0] . '">' . $menu_row[1] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[2] . '">' . $menu_row[3] . '</a> </li> </ul> </div> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[4] . '">' . $menu_row[5] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[6] . '">' . $menu_row[7] . '</a> </li> </ul> </div> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[8] . '">' . $menu_row[9] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[10] . '">' . $menu_row[11] . '</a> </li> </ul> </div> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[12] . '">' . $menu_row[13] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[14] . '">' . $menu_row[15] . '</a> </li> </ul> </div> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[16] . '">' . $menu_row[17] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[18] . '">' . $menu_row[19] . '</a> </li> </ul> </div> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[20] . '">' . $menu_row[21] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[22] . '">' . $menu_row[23] . '</a> </li> </ul> </div>'; } } mysqli_free_result($r); echo '</div> </div> ...
  2. Thank you for your response Larry. I changed the code to the snippet below but it gives me an "Undefined offset" error for values 2 onward. I tried to find a solution in the book as well as online without any success. Regards. ... <div class="dropdown-menu"> <div class="mega-dropdown-menu row row-no-padding">'; // Retrieve all the languages and add to the pull-down menu: $q = "SELECT id, lang FROM languages WHERE status='Active' ORDER BY lang ASC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { $menu_row = mysqli_fetch_array($r, MYSQLI_NUM); echo '<div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[0] . '">' . $menu_row[1] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[2] . '">' . $menu_row[3] . '</a> </li> </ul> </div> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[4] . '">' . $menu_row[5] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[6] . '">' . $menu_row[7] . '</a> </li> </ul> </div> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[8] . '">' . $menu_row[9] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[10] . '">' . $menu_row[11] . '</a> </li> </ul> </div> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[12] . '">' . $menu_row[13] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[14] . '">' . $menu_row[15] . '</a> </li> </ul> </div> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[16] . '">' . $menu_row[17] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[18] . '">' . $menu_row[19] . '</a> </li> </ul> </div> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[20] . '">' . $menu_row[21] . '</a> </li> <li><a class="dropdown-item" href="?lid=' . $menu_row[22] . '">' . $menu_row[23] . '</a> </li> </ul> </div>'; } mysqli_free_result($r); echo '</div> </div>'; ...
  3. Yes, the last code snippet above displays the language results alphabetically and horizontally across the 6 columns in the drop down menu as follow: Deutsch English (UK) English (US) Español Français Italiano Nederlands Português Pусский Ελληνικά 中文 日本の But I want the language results to display alphabetically and vertically across the 6 columns as follow: Deutsch English (US) Français Nederlands Pусский 中文 English (UK) Español Italiano Português Ελληνικά 日本の The result should also provide for additional languages to be added to the database at a later stage. Thank you and regards.
  4. The code I included above has been updated to the code below so that the languages now populate the mega drop-down menu perfectly - alphabetically and horizontally - across six columns. However, I want the languages to populate the menu alphabetically but vertically across the six columns. Is it possible to manipulate the MySQL result accordingly? I couldn't find a working example anywhere. <!-- Navbar links --> <?php // Select a language: echo '<li class="nav-item nav-item-icon hidden-md-down dropdown megamenu"> <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . $words['lang'] . ' <span><i class="fa fa-globe"></i></span></a> <div class="dropdown-menu"> <div class="mega-dropdown-menu row row-no-padding">'; // Retrieve all the languages and add to the pull-down menu: $q = "SELECT id, lang FROM languages WHERE status='Active' ORDER BY lang ASC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo '<div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li><a class="dropdown-item" href="?lid=' . $menu_row[0] . '">' . $menu_row[1] . '</a> </li> </ul> </div>'; } } mysqli_free_result($r); echo '</div> </div> </li>';
  5. Hi Larry, It took me a while but I finally got it!:) I moved the code defining the $words variable from the header.html script to the mysql.inc.php script and the $page_title variable now updates perfectly! Thank you so much for your time and patience and for getting me to finally understand the logic! Regards.
  6. Hi Larry, The code below defining the $words variable has been included in my header.html script above the <!DOCTYPE html> declaration (as per Chapter 17 - Forum). The language functionality works perfectly fine across my web app except for in the page title where it gives the "Undefined index" error. Regards. // Look for a language id: // Then store the language ID in the session: if (isset($_GET['lid']) && filter_var($_GET['lid'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) { $_SESSION['lid'] = $_GET['lid']; } elseif (!isset($_SESSION['lid'])) { $_SESSION['lid'] = 1; // Default. } // Get the words for selected language: $q = "SELECT * FROM words WHERE lang_id = {$_SESSION['lid']}"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) == 0) { // Invalid language ID. // Use the default language: $_SESSION['lid'] = 1; // Default. $q = "SELECT * FROM words WHERE lang_id = {$_SESSION['lid']}"; $r = mysqli_query($dbc, $q); } // Fetch the results into a variable: $words = mysqli_fetch_array($r, MYSQLI_ASSOC); // Free the results: mysqli_free_result($r);
  7. Hi Larry, I have tested the $words variable before and after including the header.html file. The error I referred to previously occurred with the $words variable being populated after including the header.html file. When populating the $words variable before including the header.html file, I get the following error: "Undefined variable: words". I include the code snipped below. Regards. <?php // Require the configuration before any PHP code as the configuration controls error reporting: require('includes/config.inc.php'); // The config file also starts the session. // Require the database connection: require(MYSQL); // Include the page title: $page_title = $words['signin']; // Include the HTML header file: include('templates/header.html'); // Array for storing sign up errors: $reg_errors = array(); // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] === 'POST') { ...
  8. Hi Larry, Thank you for your reply and apologies for my poor explanation! I will continue to search for a solution and post it once I found one. Regards.
  9. Hi Larry, Sorry for the oversight, I have added the words to the database. But there still seems to be an issue as the code now displays the default page title. It doesn't seem to pick up the $words variable. Any further suggestions would be much appreciated. Thank you.
  10. Hi Larry, Thank you for your response. I have included the $page_title variable in all the applicable php scripts. However the code below gives an "Undefined index: signup" error. // Include the page title: $page_title = $words['signup'];
  11. Hi Larry, Thank you for your prompt response. The code works perfectly except that it only populates the first column instead of populating across 6 columns. Regards.
  12. Hi All. I want to update my page titles dynamically with the applicable title in the selected language (Chapter 17 - Forum). I have searched the web without success. My code below shows the default "Website Name". Any help will be much appreciated. Regards. header.html snippet <!-- Page title --> <title><?php // Use the default page title if one was not provided: if (isset($page_title)) { echo $page_title; } else { echo 'Website Name'; } ?></title> signup.php snippet // Include the page title: $page_title = $words['signup'];
  13. Hi all. I need some assistance with dynamically populating a mega drop-down menu across 6 columns (Bootstrap 4) with the languages retrieved from a database query (Forum project - Chapter 17). I have searched the internet without any success. Any help will be much appreciated. My code is included below. Regards // Select a language: echo '<li class="nav-item nav-item-icon hidden-md-down dropdown megamenu"> <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . $words['lang'] . ' <span><i class="fa fa-globe"></i></span></a> <div class="dropdown-menu"> <div class="mega-dropdown-menu row row-no-padding"> <div class="col-md-4 col-lg-2 ml-lg-auto"> <ul class="megadropdown-links"> <li>'; // RetrRetrieve all the languages and add to the pull-down menu: $q = "SELECT id, lang FROM languages WHERE status='Active' ORDER BY lang ASC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo '<a class="dropdown-item" href="?lid=' . $menu_row[0] . '">' . $menu_row[1] . '</a>'; } } mysqli_free_result($r); echo '</li> </ul> </div> </div> </div> </li>';
  14. Hi Larry, Thank you very much for your prompt response. I tried your suggestion without any luck, so I redid the pagination from scratch for the umpteenth time and I finally found my error! I included the active <li class> on line 485 instead of line 505. A really silly error! I include the correct code below. Kind regards. // Add pagination if necessary: if ($pages > 1) { echo '<nav aria-label="page navigation"> <ul class="pagination pagination-sm">'; $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button: if ($current_page != 1) { echo '<li class="page-item"> <a class="page-link" href="view_users.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '" aria-label="Previous">«</a></li>'; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<li class="page-item"><a class="page-link" href="view_users.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a></li>'; } else { echo '<li class="page-item active"><a class="page-link" href="#">' . $i . '</a></li>'; } } // End of FOR loop. // If it's not the last page, make a Next button: if ($current_page != $pages) { echo '<li class="page-item"><a class="page-link" href="view_users.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '" aria-label="Next">»</a></li>'; } echo '</ul> </nav>'; } // End of pagination section.
  15. Hi Larry, Thank you very much for your unequivocal answers. I have implemented your suggestions successfully! I unfortunately have the following issue with the pagination that I can't seem to resolve. I am using Bootstrap 4. The pagination displays correctly when the page is initially loaded, with page 1 being the active page, but when the sequential page numbers are clicked, they displays in sequence but outside of the Bootstrap 4 <li> tag. I include my code below. Any suggestions to correct the error will be much appreciated. Regards. // Add pagination if necessary. if ($pages > 1) { echo '<nav> <ul class="pagination pagination-sm"> <li class="page-item active"> <a class="page-link" href="#"><span class="sr-only">'; $current_page = ($start/$display) + 1; echo '</span>'; // If it's not the first page, make a Previous link: if ($current_page != 1) { echo '</a></li> <li class="page-item"> <a class="page-link" href="view_users.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '" tabindex="-1">«</a> </li>'; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<li class="page-item"><a class="page-link" href="view_users.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> </li>'; } else { echo $i . ' '; } } // End of FOR loop. // If it's not the last page, make a Next link: if ($current_page != $pages) { echo '<li class="page-item"><a class="page-link" href="view_users.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">»</a>'; } echo '</li> </ul> </nav>'; // Close pagination. } // End of links section.
×
×
  • Create New...