Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Database menu?

  1. #1
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    919
    Thanks
    76
    Thanked 29 Times in 29 Posts

    Question Database menu?

    Hello,

    I am wondering if it is possible to save menu links within a database and then retrieve the links to be displayed within my menu div?

    If so, can it be possible that when that link is clicked, it takes you to another page where it shows the relative content to that link, which also displayed data relating to that link?

    I hope I have explained myself well enough.

    Kind regards,

    LC.
    Last edited by LearningCoder; 09-06-2012 at 12:36 AM. Reason: grammar

  • #2
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    919
    Thanks
    76
    Thanked 29 Times in 29 Posts
    Really, no-one?

    LC.

  • #3
    New Coder
    Join Date
    Sep 2012
    Posts
    71
    Thanks
    0
    Thanked 8 Times in 8 Posts
    I'm not sure exactly what you mean but I'll throw something out there and see if that helps get things moving for you.

    You could certainly query a set of links from a database to show on a page:

    PHP Code:
    $pageid mysql_real_escape_string(...);
    $sql "select link_url, link_text from menu_links where pageid = '$pageid'";
    if ( !
    $res mysqli_query($link,$sql) )
       die(
    "ERROR: Unable to query menu links!\n");

    $list = array();
    while ( 
    $row=mysqli_fetch_assoc($res) )
       
    $list[] = $row;
    mysqli_free_result($res);

    foreach (
    $list as $row)
    {
       
    $link_url $row['link_url'];
       
    $link_text $row['link_text'];

       echo 
    "<a href=\"$link_url\">$link_text</a><br>\n";

    Beware, this is not actual code, just typed in on the fly. So there may be some errors in there.

  • #4
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    919
    Thanks
    76
    Thanked 29 Times in 29 Posts
    Ah I believe this is what I am looking for. So you retrieve a "nav menu" essentially.

    Would it be better to just type a HTML/CSS menu? I basically want maybe 1-2 links which when clicked will open up a page and show the relative content for that link.

    I am wondering also about relationships between database tables.

    My aim here is to create a gaming site to upload demorecs. I want it to be database driven. Would I have to create a separate table for each game's files? That doesn;t really sound the correct way to me, but i'm not sure.

    Thanks for the reply.

    Regards,

    LC.

  • #5
    New Coder
    Join Date
    Sep 2012
    Posts
    71
    Thanks
    0
    Thanked 8 Times in 8 Posts
    Well, I'm not informed enough to suggest what might be better in your situation. However, if you wanted to track a bunch of games and some information for each of those games you'd want something like:

    games
    ------
    game_id
    game
    game_x
    game_y
    created

    gameinfo
    --------
    info_id
    game_id
    info_x
    info_y
    created
    Then, you could show a list of games as a "menu" and once you picked a game a list of "info" items as a "menu"... taking you to the page of info, for example.

    You could also added an info comment table if you wanted:

    infocomment
    ------------
    ic_id
    info_id
    comment
    created_by
    created
    Hopefully, if you set things up nicely, the HTML/CSS portions are mostly defined outside of your code and you place the table based output into your page.

    Hint, it is often nice to accumulate your output instead of echoing in place. If you create a function which returns the output as a string... you can easily move the output to any part of your page or to another page without having to physically move the entire chunk of code.

    So, for example:

    PHP Code:
    $gamemenu get_game_menu($dblink);   // Prepare list of games as a link list
    echo $gamemenu


  •  

    Posting Permissions

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