Data display in PHP dynamic menu with no results

Asked

Viewed 30 times

0

Hello.

I am from the beginning of the week trying to finish the dynamic menu I created but I can’t display the div corresponding to the link as well as its contents.

Describing better, I have a submenu with the continents and each of them should open a div with another submenu containing the respective countries. So far I can display the results in the submenu of the continents but then I can’t open the country Ivs.

With tiredness and motivation descending, I ask you which way to go, because I have tried several solutions and I cannot solve the problem.

Below I have the code in PHP, mod_menu.php:

<?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
?>

<div id="container">
    <ul class="nav">
        <li><a href="index.php">home</a></li>                 
        <li>
          <a href="#" id="destinations">destinations</a>
<div id="subMenu">                   
<?php 
    $servername = "localhost:3306";
    $username = "root";
    $password = "";
    $dbname = "site_comboios";

    //Abre ligação à BD
    $mysqli = new mysqli($servername, $username, $password, $dbname);

//check connection
if($mysqli->connect_errno) {
    echo 'Error connecting to database';
    exit();
         }

//show sub-menu
$query = "SELECT * FROM continentes ORDER BY id";
$result = mysqli_query($mysqli, $query);     
    while ($row = mysqli_fetch_assoc($result)) {
          $Cont = $row['continente'];
echo "<div class='nav-column'><a href='#cnt_submenu' data-id='<?php   $query ?>' class='continente'>" .($Cont). "</a></div> ";    
        }
 ?>                      

 </div>                    
    </li>                
    <li><a href="#about">about</a></li>
    <li><a href="#contact">contact</a></li>
  </ul>         
 </div> 

<div id="cnt_submenu" data-id="divSub" class="submenu_continente  active">    
<?php
//retrieve european countries from DB and open <ul> with 9 results
$conn = mysqli_connect("localhost:3306","root","","site_comboios");
$sql_eurCountries = "SELECT * FROM countries ORDER BY id WHERE   id_continentes = 1";
$result_eurCountries = mysqli_query($conn, $sql_eurCountries);

if($result_eurCountries > 0) { 
    while ($row_eurCountries = mysqli_fetch_assoc($result_eurCountries))   {
    $país_Eur = $row_eurCountries['id_continentes'];
    echo "<ul><li><a href='#'>". $país_Eur ."</a>";
}

} else if ($result_eurCountries == 9) {
       echo '</li></ul>';
       }
?>
<span class="close">x</span>
</div>

<div id="cnt_submenu" data-id="divSub" class="submenu_continente active">
<?php
//retrieve african countries from DB  
$sql_afrCountries = "SELECT * FROM countries ORDER BY id WHERE   id_continentes = 2";
$result_afrCountries = mysqli_query($conn, $sql_afrCountries);

while ($row_afrCountries = mysqli_fetch_assoc($result_afrCountries)) {
     $pais_Afr = $row_afrCountries['id_continentes'];
     echo "<ul><li><a href='#'>". $pais_Afr ."</a></li></ul>";
      }
 ?>
 </div>

<div id="cnt_submenu" data-id="divSub" class="submenu_continente active">
<?php
//retrieve asian countries from DB 
$sql_asiaCountries = "SELECT * FROM countries ORDER BY id WHERE  id_continentes = 3";
$result_asiaCountries = mysqli_query($conn, $sql_asiaCountries);

if($sql_asiaCountries == FALSE) {
      die(mysqli_errno($conn));
      }

while ($row_asiaCountries = mysqli_fetch_assoc($result_asiaCountries)) {
      $pais_Asia = $row_asiaCountries['id_continentes'];
      echo "<ul><li><a href='#'>". $pais_Asia ."</a></li></ul>";
      }

?>
</div>

<div id="cnt_submenu" data-id="divSub" class="submenu_continente active">
<?php
//retrieve oceania countries from DB 
$sql_oceaCountries = "SELECT * FROM countries ORDER BY id WHERE id_continentes = 4";
$result_oceaCountries = mysqli_query($conn, $sql_oceaCountries);

if($sql_oceaCountries == FALSE) {
       die(mysqli_errno($conn));
      }

while ($row_oceaCountries = mysqli_fetch_assoc($result_oceaCountries)) {
    $pais_Oceania = $row_oceaCountries['id_continentes'];
    echo "<ul><li><a href='#'>". $pais_Oceania ."</a></li></ul>";
      }
?>
</div>

<div id="cnt_submenu" data-id="divSub" class="submenu_continente  active">
<?php
//retrieve north america countries from DB 
$sql_norCountries = "SELECT * FROM countries ORDER BY id WHERE  id_continentes = 5";
$result_norCountries = mysqli_query($conn, $sql_norCountries);

if($sql_norCountries == FALSE) {
    die(mysqli_errno($conn));
    }

while ($row_norCountries = mysqli_fetch_assoc($result_norCountries)) {
$pais_North = $row_norCountries['id_continentes'];
echo "<ul><li><a href='#'>". $pais_North ."</a></li></ul>";
}
?>
</div>

<div id="cnt_submenu" data-id="divSub" class="submenu_continente  active">
<?php
//retrieve south america countries from DB 
$sql_sulCountries = "SELECT * FROM countries ORDER BY id WHERE  id_continentes = 6";
$result_sulCountries = mysqli_query($conn, $sql_sulCountries);

if($sql_sulCountries == FALSE) {
      die(mysqli_errno($conn));
     }

while ($row_sulCountries = mysqli_fetch_assoc($result_sulCountries)) {
      $pais_South = $row_sulCountries['id_continentes'];
      echo "<ul><li><a href='#'>". $pais_South ."</a></li></ul>";
}
?>
</div>

And the jQuery code that displays the respective div according to each continent:

$('.continente').hover(function(){
    var subCountry = $(this).data('id');
    $('divSub').show(subCountry);
        });

Apart from not showing any div, in PHP I have the following error:

"mysqli_fetch_assoc expects Parameter 1 to be mysqli_result Boolean Given in"

Regarding this error, I tried to create a BD connection on each subDiv, but the error persisted.

I appreciate your help.

  • http://answall.com/a/187430/3635

  • Try to change SELECT * FROM countries ORDER BY id WHERE id_continentes = 1 for SELECT * FROM countries WHERE id_continentes = 1 ORDER BY id.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.