2016-07-11 5 views
0

PHPを使用する

//Set the database connection 
    ($GLOBALS["___mysqli_ston"] = mysqli_connect('localhost', 'root', 'chethan')); 
    ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . 'bigdata')); 
    //select all rows from the main_menu table 
    $result = mysqli_query($GLOBALS["___mysqli_ston"], "select id,title,parentid,link from main_menu"); 

    //create a multidimensional array to hold a list of menu and parent menu 
    $menu = array(
     'menus' => array(), 
     'parent_menus' => array() 
    ); 

    //build the array lists with data from the menu table 
    while ($row = mysqli_fetch_assoc($result)) { 
     //creates entry into menus array with current menu id ie. $menus['menus'][1] 
     $menu['menus'][$row['id']] = $row; 
     //creates entry into parent_menus array. parent_menus array contains a list of all menus with children 
     $menu['parent_menus'][$row['parentid']][] = $row['id']; 
    } 

    // Create the main function to build milti-level menu. It is a recursive function. 
    function buildMenu($parent, $menu) { 
    $html = ""; 
    if (isset($menu['parent_menus'][$parent])) { 
     $html .= "<ul>"; 
     foreach ($menu['parent_menus'][$parent] as $menu_id) { 
      if (!isset($menu['parent_menus'][$menu_id])) { 
       $html .= "<li><a href='" . $menu['menus'][$menu_id]['link'] . "'>" . $menu['menus'][$menu_id]['title'] . "</a></li>"; 
      } 
      if (isset($menu['parent_menus'][$menu_id])) { 
       $html .= "<li><a href='" . $menu['menus'][$menu_id]['link'] . "'>" . $menu['menus'][$menu_id]['title'] . "</a>"; 
       $html .= buildMenu($menu_id, $menu); 
       $html .= "</li>"; 
      } 
     } 
     $html .= "</ul>"; 
    } 
    return $html; 
} 
+0

このデータベースを選択してくださいmysqli_select_db($ GLOBALS ["___ mysqli_ston"]、 'bigdata'); (bool)mysqli_query($ GLOBALS ["___ mysqli_ston"]、 "USE"、 "bigdata")); – JYoThI

+0

mysqli_query($ GLOBALS ["___ mysqli_ston"]、 "USE"、 "bigdata"); – JYoThI

+0

Bro ....それは働いた...ありがとう感謝! –

答えて

0

このこの

mysqli_select_db($GLOBALS["___mysqli_ston"], 'bigdata'); 

instedなどの選択データベース

((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . 'bigdata')); 
関連する問題