Jump to content

moonshine

New Members
  • Posts

    4
  • Joined

  • Last visited

moonshine's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Update it's not working as it should because now it only displays the first menu and his sub-menus and the update works only for the menu and his first sub-menu .
  2. CREATE TABLE `lab4`.`menus` ( `ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `Menu_bar` VARCHAR( 100 ) NOT NULL , `Parent_id` INT NOT NULL ) ENGINE = MYISAM ; ID Menu_bar Parent_id 1 Home 0 2 News 0 3 Events 2 4 Places 2 5 Contact 0 So Events and Places are the sub-menus of News. Yes all of the parent menus have Parent_id=0 and the sub-menus have the Parent_id equal to their parent unique ID . With only one while loop it works perfect but all of the items are dispalyed like a table and it should look like a menu .
  3. I'm trying to figure it out why my code it's only updating the last menu or submenu of a menu. The menu and submenu are stored in the same database and the parent_id is equal to the id for the sub-menus . Parent_id = 0 means it's a main menu. Help! $con = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $con); if(isset($_POST['update'])) { $sql = "UPDATE `menus` SET Menu_bar = '".$_POST['menu_bar']."' WHERE ID = ".$_POST['hidden']; mysql_query( $sql, $con ); } $resultMainMenu = mysql_query("SELECT * FROM menus WHERE Parent_id=0 ") or die(mysql_error()); echo '<form action=page.php method=post>'; while($row = mysql_fetch_assoc($resultMainMenu)) { echo '<ul>'; echo "<li><input type=submit name=update value=update><input type=hidden name=hidden value='".$row['ID']."'><input type=text name=menu_bar value='".$row['Menu_bar']."'><br/>" ; // echo main menu $resultSubmenu = mysql_query("SELECT * FROM menus WHERE Parent_id = " . $row['ID']) or die(mysql_error()); echo '<ul>'; while($rowSub = mysql_fetch_assoc($resultSubmenu)) { echo "<li><input type=submit name=update value=update><input type=hidden name=hidden value='".$rowSub['ID']."'><input type=text name=menu_bar value='".$rowSub['Menu_bar']."'><br/></li>"; // echo sub menu } echo '</ul>'; echo '</li>'; echo'</ul>'; } echo '</form>'; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.