parodys Posted February 7, 2009 Share Posted February 7, 2009 Hey guys, I kinda new to PHP and mySQL, ive mastered HTML ( big woop eh ) now its time to get into proper coding etc and so ive been pointed to this forum to get some help! Here goes, i have a database that has table such as this : id, title, article, cat, created_at what i am trying to do is make a menu on the left side of my webpage, that will have a make a list of the all the cat, and once clicked will go to a page that lists all the articles under that cat. Would it be easier to create a relational database to correspond with the cat ? or make a function that will scan the cat table and out put a list of single cats? Im not sure if ive gone about this the right way, but ive made the structure like this. index.php <?php include('dbfuncs.php'); $controller = 'articles'; $view = empty($_GET['view']) ? 'index' : $_GET['view']; switch ($view) { case "index": $layout = 'home'; break; case "article": $layout = 'articles'; break; case "archive": echo "this is the archive page"; break; case "new": echo "this is the NEW page"; break; } if(isset($layout)) { include ($_SERVER['DOCUMENT_ROOT'].'/codedad/views/layouts/'.$layout.'.php'); } else { include ($_SERVER['DOCUMENT_ROOT'].'/codedad/views/layouts/'.$controller.'.php'); } ?> which is pretty much my templating system and web site layout. So if i type in wxw.codedad.com/?view=article it will take me to the the article page... and in that template ill have calls to functions that will display the data. It works well so far. but yeah im have trouble creating a menu for the cats. Obviously i have a lot of learning to do.. haha Any ideas or linkage to some info would be oh so appreciated !! Quote Link to comment https://forums.phpfreaks.com/topic/144159-solved-help-with-making-a-menu-from-a-database-table/ Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 since u mastered html why don't u create demo page.. * what should u see in 1st page * what should u see after click one of the menu * what should u see after click another in menu for me, i were begin the new app with modul ex: u want to show all cat on menu.. * i create modul to show all cat and it show only text only no link and no graph in it (GUI) * i update with link * i put on the HTML etc Quote Link to comment https://forums.phpfreaks.com/topic/144159-solved-help-with-making-a-menu-from-a-database-table/#findComment-756487 Share on other sites More sharing options...
parodys Posted February 7, 2009 Author Share Posted February 7, 2009 yeah i have created a basic layout demo, thats what ive been working off. Just having trouble creating a menu for all the categories under cat from my database. In the database i have over 200 pages listed under 8 categories. so i need the menu to go like this. The trouble im having is making the actual menu from the CAT table in the database and then forwarding it to the archive page (paginated of cause) where it will list all the articles under the cat and once clicked on will go again to the actual article page. it probably simple stuff i just cant seem to get my head around it. Quote Link to comment https://forums.phpfreaks.com/topic/144159-solved-help-with-making-a-menu-from-a-database-table/#findComment-756498 Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 hmm.. allright.. u already built the page but view your table.. i was think u need learn much about database, table etc well, there's a long road u must follow.. but don't worry.. you will pass it. let me honest to you. create only one table to this site is good.. but create more table with link betwen.. IS BETTER ^^ perhaps u should read about "Normalitation" sry.. i can help you.. but i try to give u a lure than give you the fish *do you understand? Quote Link to comment https://forums.phpfreaks.com/topic/144159-solved-help-with-making-a-menu-from-a-database-table/#findComment-756579 Share on other sites More sharing options...
parodys Posted February 7, 2009 Author Share Posted February 7, 2009 ok haha ive looked it up. I created a new table table name : cat id, cat i joined them but when i query it i get a list of all the articles cats.. php php php php and so on. $query = "SELECT articles.cat, cat.cat FROM articles, cat WHERE articles.cat = cat.cat"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['cat']; } hmmm Quote Link to comment https://forums.phpfreaks.com/topic/144159-solved-help-with-making-a-menu-from-a-database-table/#findComment-756627 Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 ehem.. u said in top to build menu ? <?php ...... /*just header etc*/ $query = "SELECT cat.cat FROM cat order by cat"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['cat']; } ?> this menu you wish ^^ hehehe.. rokie mistake.. well.. before leave.. try to give a better name for field ex: table Category: field: catid, catname, catdesc this will give you a better understanding about the table/field u use.. btw.. cat can mean an animal cat ^^ Quote Link to comment https://forums.phpfreaks.com/topic/144159-solved-help-with-making-a-menu-from-a-database-table/#findComment-756647 Share on other sites More sharing options...
parodys Posted February 7, 2009 Author Share Posted February 7, 2009 haha yeah good point ive made the changes to the database and have been thinking about it. If i do a query for the categories to be listed in an unordered list, with links that will pass the value of the category to the archive page and in turn will it list the articles under that category ? maybe using a $_get ? and isset ? haha am i on the right track ? Quote Link to comment https://forums.phpfreaks.com/topic/144159-solved-help-with-making-a-menu-from-a-database-table/#findComment-756652 Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 yes.. you are on the right track fyi.. this conclude the menu u want to build.. next stop view all doc related to that category Quote Link to comment https://forums.phpfreaks.com/topic/144159-solved-help-with-making-a-menu-from-a-database-table/#findComment-756678 Share on other sites More sharing options...
parodys Posted February 8, 2009 Author Share Posted February 8, 2009 ok so ive made some progress, im not sure if ive done this the optium way, but its getting there slowly! <?php // displays catogories and makes a list with links to archive page db_connect(); $query = "SELECT catname FROM category"; $result = mysql_query($query) or die(mysql_error()); // make the catogories list $entry = '<ul>'; while ($row = mysql_fetch_array($result, MYSQL_NUM)) { list($catname) = $row; $entry .= "<li><a href=\"$catname\">$catname</a></li>\r\n"; } $entry .= '</ul>'; // show the catogories list echo $entry ?> It lists the catogories now all i have to do is figure how to pass the the cat id along thanks for your help so far ! Quote Link to comment https://forums.phpfreaks.com/topic/144159-solved-help-with-making-a-menu-from-a-database-table/#findComment-757319 Share on other sites More sharing options...
landavia Posted February 9, 2009 Share Posted February 9, 2009 ur welcome and please remember.. since u still beginner.. don't think about security until u want publish it to NET Quote Link to comment https://forums.phpfreaks.com/topic/144159-solved-help-with-making-a-menu-from-a-database-table/#findComment-758234 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.