How can I put submenu inside a menu from a database

Asked

Viewed 228 times

-1

I have the tables in the database well done, but then when I do the code, the content doesn’t even appear, I wish I had help sff

the code I have is this:

$resultado = mysql_query("SELECT titulo FROM menu WHERE id_menu = 1 ORDER BY id_menu   ") or die(mysql_error());
while($linha = mysql_fetch_array($resultado)) {
   echo "<li> ".$linha[''] . " " . $home ." </li>";
} 

$resultado = mysql_query("SELECT titulo FROM menu WHERE id_menu = 2 ORDER BY id_menu   ") or die(mysql_error());
$result = mysql_query("SELECT titulo FROM submenu WHERE id_submenu = 2 ORDER BY id_submenu   ") or die(mysql_error());
while($linha = mysql_fetch_array($resultado)) {
   echo " <li class= 'dropdown ' > 
  <a  echo $orgaosMenu;  href='#' class='dropdown-toggle' data-toggle='dropdown' style='padding-top: 15px;border-top: 0px solid #3B7D26;'>" . $linha['titulo'] . "<b class='caret'></b></a>
     " . $orgaosMenu . "</li>";

     while($line = mysql_fetch_array($result)){
      echo "<ul class='dropdown-menu'> 
      <li>   " .$line['titulo'] . "   </li>";
     }
} 

$resultado = mysql_query("SELECT titulo FROM menu WHERE id_menu = 3 ORDER BY id_menu   ") or die(mysql_error());
while($linha = mysql_fetch_array($resultado)) {
   echo " <li class= 'dropdown ' > 
  <a  echo $autarcasMenu;  href='#' class='dropdown-toggle' data-toggle='dropdown' style='padding-top: 15px;border-top: 0px solid #3B7D26;'>" . $linha['titulo'] . "<b class='caret'></b></a>
     " . $autarcasMenu . "</li>";
} 

$resultado = mysql_query("SELECT titulo FROM menu WHERE id_menu = 4 ORDER BY id_menu   ") or die(mysql_error());
while($linha = mysql_fetch_array($resultado)) {
   echo " <li class= 'dropdown ' > 
   <a  echo $militanciaMenu;  href='#' class='dropdown-toggle' data-toggle='dropdown' style='padding-top: 15px;border-top: 0px solid #3B7D26;'>" . $linha['titulo'] . "<b class='caret'></b></a>
     " . $militanciaMenu . "</li>";
}     

$resultado = mysql_query("SELECT titulo FROM menu WHERE id_menu = 5 ORDER BY id_menu   ") or die(mysql_error());
while($linha = mysql_fetch_array($resultado)) {
   echo " <li  > 
  <a  echo $multimediaMenu;  href='#' class='dropdown-toggle' data-toggle='dropdown' style='padding-top: 15px;border-top: 0px solid #3B7D26;'>" . $linha['titulo'] . "<b ></b></a>
     " . $multimediaMenu . "</li>";
}    

$resultado = mysql_query("SELECT titulo FROM menu WHERE id_menu = 6 ORDER BY id_menu   ") or die(mysql_error());
while($linha = mysql_fetch_array($resultado)) {
   echo " <li  > 
  <a  echo $contactosMenu;  href='http://www.w3schools.com/php/php_mysql_where.asp' class='dropdown-toggle' data-toggle='dropdown' style='padding-top: 15px;border-top: 0px solid #3B7D26;'>" . $linha['titulo'] . "<b ></b></a>
     " . $contactosMenu . "</li>";
}
?>
  • I really need help, please....

  • add these two lines at the beginning of the file: ini_set('display_errors', true);&#xA; error_reporting(E_ALL); and place error messages.

  • this line here already issues a notice: echo "<li> ".$linha[''] . " " . $home ." </li>"; an information should be accessed, I believe it would be $linha['titulo'].

  • it would be nice to pass the design of the database..

1 answer

0

It seems to me that the problem is in mysql_fetch_array()... It does not associate the column name to the array and so you cannot access $line['title']... Try using mysql_fetch_assoc($result) or mysql_fetch_array($result,MYSQL_ASSOC);

  • I didn’t quite understand what he said, my problem lies in the while it is inside the other while, it just doesn’t put the results I ask

  • Try closing the tag ul Where you have: while($line = mysql_fetch_array($result)){ echo "<ul class='dropdown-menu'> <li> " . $line['title'] . "</li>"; } adds at the end echo "</ul>";

  • a question... the tag ul should be out of while?

  • Yes! but in the final code for each </li> (list item) you closed would close to <ul> (unordered list)

  • The solution worked?

  • No, the function has not solved, and I do not find the error

Show 1 more comment

Browser other questions tagged

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