www.webdeveloper.com
Results 1 to 11 of 11

Thread: A little school help

  1. #1
    Join Date
    Mar 2012
    Posts
    7

    A little school help

    A have a simple task here.
    Its easy to complete but there`s some snares.
    Please give me some advice how to create it and what to drew attention.
    Thanks to everyone !

    Here is the tast with the picture inside
    http://www.mediafire.com/?7xj656uh9vdb31s

  2. #2
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    I would use AJAX for this task, will make the page smoother. What are you stuck on, I will be better able to help.

  3. #3
    Join Date
    Mar 2012
    Posts
    7
    Its almost ready.. But i`m wondering one thing.
    How to create the menu
    When its clicked on the Root2 to show only the sub items,not everone in the db
    Should I use jquery ?! Because I really never used it

  4. #4
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    Are you pulling this info from a database? And what is the PHP you are using now? (Please edit out and sensitive info). And Possibly, but I need more info before I can say yes or no. @_@

  5. #5
    Join Date
    Nov 2002
    Posts
    2,632
    If this is for school, then you need to find a solution based on what technologies you are suppose to know for that class. If you aren't suppose to know jQuery, then even if you get it working you won't get it right since you found an answer that doesn't line up with what it should be.

  6. #6
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    Quote Originally Posted by spufi View Post
    If this is for school, then you need to find a solution based on what technologies you are suppose to know for that class. If you aren't suppose to know jQuery, then even if you get it working you won't get it right since you found an answer that doesn't line up with what it should be.
    Good point, I haven't been in school for like 6 years so I didn't think about it.

  7. #7
    Join Date
    Mar 2012
    Posts
    7

    Talking

    Here I am so far:

    http://vencislav.byethost13.com/index.php




    The function

    function menu()
    {
    db_init();
    if($_POST['new']==1)
    {
    $name=addslashes(trim($_POST['title']));
    $color=addslashes(trim($_POST['color']));

    $id=(int)$_POST['edit_id'];
    if($id>0)
    {
    mysql_query('UPDATE sub
    SET name_sub="'.$name.'",color="'.$color.'"
    WHERE id_sub="'.$id.'" ');
    }
    else
    {
    mysql_query('INSERT INTO sub (name_sub,color)
    VALUES ("'.$name.'","'.$color.'")');
    }

    }

    $rs=mysql_query('SELECT * FROM Main');
    while($row=mysql_fetch_assoc($rs))
    {
    echo $row['name'].'<br />';
    }

    $rs=mysql_query('SELECT * FROM sub');
    echo '<p>';
    while($row=mysql_fetch_assoc($rs))
    {
    echo '<a href="index.php?mode=edit&id_sub='.$row['id_sub'].'" style="color:'.($row['color']).' ">'.$row['name_sub'].'</a><br />';
    }
    echo '</p>';

    if($_GET['mode']=="edit" && $_GET['id_sub']>0)
    {
    $id=(int)$_GET['id_sub'];
    $rs=mysql_query('SELECT * FROM sub WHERE id_sub='.$id);
    $ed_info=mysql_fetch_assoc($rs);
    }


    echo '<form method="post" action="index.php">
    Title:<input type="text" name="title" value="'.$ed_info['name_sub'].'"/><br />
    Color:<select name="color">
    <option>black</option>
    <option>red</option>
    <option>green</option>
    <option>blue</option>
    <option>yellow</option>
    <option>cyan</option>
    <option>magenta</option>
    <option>silver</option>
    <option>white</option>
    </select>
    <input type="submit" value="submit"/>
    <input type="hidden" name="new" value="1">';

    if($_GET['mode']=="edit")
    {
    echo '<input type="hidden" name="edit_id" value="'.$_GET['id_sub'].'">';
    }

    }

    I have a few questions to you.

    How can I add the new items to the Root1 Root2 Root3
    How can I list them like in the task.
    When I click Root1 to see only the items which are related to root1.


    In my DB there are 2 tables

    Table main
    id_root name color
    Auto in Root1 black
    Auto in Root2 black
    Auto in Root3 black

    Table sub
    id_sub name_sub color parent
    Auto in test magenta 0
    Auto in dobre blue 0
    Auto in welcome! green 0

    I need to make them connected to the parent:root1,2,3 or themself

    I really dont think I need 2 tables,right ?!

  8. #8
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    Do do the trees properly, without Javascript/jQuery, you are going to want to use the GET method to get the sub cats. For example:
    PHP Code:
    if(isset($_GET['root'])){
    $rootid $_GET['root'];
    $tree mysql_query("SELECT * FROM $db.$table WHERE sub_id = '$rootid'");
    $sub '';
    while(
    $fulltree mysql_fetch_array($tree)){
    $sub .= '<a href="?root='.$rootid.'&sub='.$fulltree['id'].'">'.$fulltree['name'].'</a>';
    }} 
    Try seeing if you can modify that to fit your needs. I would write it for you but then you will never learn. XD

  9. #9
    Join Date
    Nov 2002
    Posts
    2,632
    If I understand this correctly...
    Code:
    Table root
        id, name, color
    
    Table submenu
        id, rootid, name, color.
    
    1. Select for each root item.
    2. Loop through the resulting array.
        a. Display each root item.
        b. Select from submenu where root.id = rootid.
        c. Loop through resulting array
            i. Display each submenu item.

  10. #10
    Join Date
    Mar 2012
    Posts
    7
    I was in a mistake.
    There is no root...
    I need only one table.
    It should look like this:

    Item1
    Item2
    --Item3(child of Item2)
    Item4
    --Item5(child of Item4)
    --Item6(child of Item4)
    ----Item7(child of Item6)
    ----Item8(child of Item6)
    ------Item9(child of Item8)

    and so on....

    There`s no problem to write the parent ID in the DB when create new item.
    The question is how to draw the tree.
    Should I use a recursion?
    I must start the recursion and calling it every time when there is some deeper Item on the tree.
    I can`t figure it out how it should be made

  11. #11
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Some reading material for the weekend, after which you can decide which technique is right for this implementation: http://mikehillyer.com/articles/mana...data-in-mysql/
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles