Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-06-2012, 12:35 AM   PM User | #1
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
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
LearningCoder is offline   Reply With Quote
Old 09-06-2012, 08:22 AM   PM User | #2
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
Really, no-one?

LC.
LearningCoder is offline   Reply With Quote
Old 09-06-2012, 11:53 AM   PM User | #3
vroom
New Coder

 
Join Date: Sep 2012
Posts: 71
Thanks: 0
Thanked 8 Times in 8 Posts
vroom is an unknown quantity at this point
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.
vroom is offline   Reply With Quote
Old 09-07-2012, 02:26 AM   PM User | #4
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
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.
LearningCoder is offline   Reply With Quote
Old 09-07-2012, 01:59 PM   PM User | #5
vroom
New Coder

 
Join Date: Sep 2012
Posts: 71
Thanks: 0
Thanked 8 Times in 8 Posts
vroom is an unknown quantity at this point
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:

Quote:
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:

Quote:
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
vroom is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:11 AM.


Advertisement
Log in to turn off these ads.