john-formby Posted July 17, 2006 Share Posted July 17, 2006 At the moment I have a CSS menu in the form of an unordered list which links to all the pages I want to display. I have a link database which holds all of the data. The table for the database is as follows:[code]CREATE TABLE `links` ( `link_id` int(11) NOT NULL auto_increment, `category_code` varchar(10) NOT NULL default '0', `link_text` varchar(254) NOT NULL default '', `url` varchar(254) NOT NULL default '', `description` text NOT NULL, `keywords` text NOT NULL, `time_added` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `new_window` tinyint(4) NOT NULL default '0', PRIMARY KEY (`link_id`)) ENGINE=MyISAM;[/code]I have created a page for every menu option which contains the following:[code]<?phpinclude("common/header1.php");?></head><body onload="initialiseMenu();"><?include("common/header2.php");?> <div id="maincol"><h1>Graphics - Advice Forums</h1><?phpinclude "dblinks.inc";$pageSize = 5;$pageNumber = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;$query="SELECT * FROM links WHERE category_code = 321 ORDER BY link_text ASC LIMIT ".(($page-1) * $pageSize).','.$pageSize;$result=mysql_query($query);while ($row = mysql_fetch_assoc($result)) {$link_text=$row['link_text'];$description=$row['description'];$url=$row['url'];$popup = ($row['new_window'] == 1);$newdes = stripslashes($description);if($popup) { $link = '<a href="'.$url.'" onclick="window.open(this.href);return false">';} else { $link = '<a href="'.$url.'" >';}echo "<hr /><br />".$link."<b>$link_text</b></a><br>$newdes<br/>".$link."$url</a><br /><br />";}echo "<hr /><br />";$numberOfRecords = mysql_result(mysql_query('SELECT count(*) FROM links WHERE category_code=321'),0,0);for($i = 0; $i < $numberOfRecords; $i += $pageSize) { $page = 1 + floor($i/$pageSize); echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$page.'"> [ '.$page.' ] </a>';}mysql_close();?><br /><br /></div><?include("common/rightcol.php");include("common/navigation.php");include("common/footer.php");?>[/code]The problem is that when I want to update something it takes me ages. I was wondering if there is some way that I can send the navigation links to one page which will display the data I require based on the category_id? It would also have to be able to create the title for the page. Something like 'Links - Web Design Tutorials'I don't want to automatically create the menu as I am happy with it the way it is, I just want to be able to automatically create the results.Here is an extract from the menu:[code]<li><a href="#">Links</a> <ul> <li><a href="#">Web Design</a> <ul> <li><a href="../lwdtutorials.php?page=1">Tutorials</a></li> <li><a href="../lwdadviceforums.php?page=1">Advice Forums</a></li> <li><a href="../lwdcodearchives.php?page=1">Code Archives</a></li> <li><a href="#">Languages</a> <ul> <li><a href="../lwdasp.php?page=1">ASP</a></li> <li><a href="../lwdcgi.php?page=1">CGI</a></li> <li><a href="../lwdcss.php?page=1">CSS</a></li> <li><a href="../lwdhtml.php?page=1">HTML</a></li> <li><a href="../lwdjavascript.php?page=1">JavaScript</a></li> <li><a href="../lwdjsp.php?page=1">JSP</a></li> <li><a href="../lwdphp.php?page=1">PHP</a></li> </ul> </li>[/code]I had a go at creating the table (which can be seen below) and altering the code but I always get errors. Please can someone help me with this.[code]CREATE TABLE `category` ( `category_code` varchar(10) NOT NULL default '0', `parent_category` varchar(10) default NULL, `description` varchar(40) NOT NULL default '', PRIMARY KEY (`category_code`)) ENGINE=MyISAM[/code]For example I made LINKS the parent category with a value with a category_code of 3, left parent_category as NULL and description as LinksI gave Web Design Tutorials a category code of 300, parent_category of 3 and description of Web Design Tutorials.I had a go at changing the navigation menu to link to one page (linkspage.php) and assigning the category_code (linkspage.php?category_id=300) The linkspage code was a modification of the code that was displayed on every page. Unfortunately it did not work and I ended up with about 50 errors, none of which I could understand.I don't know if anyone will be able to understand my ramblings, so please ask questions if you don't know what I am talking about.Thanks,John Quote Link to comment https://forums.phpfreaks.com/topic/14888-generating-pages-based-on-category_id/ Share on other sites More sharing options...
pixy Posted July 17, 2006 Share Posted July 17, 2006 Is it just me, or would it be WAY easier just to use the $_GET method, and have something like:page.php?link=1245Where 1245 or whatever refers to the category? I know you said that wasn't working, but that's really the only way I could think of doing that easily. You could still do that and pagnate the query results over several pages as you were doing in the code above. Quote Link to comment https://forums.phpfreaks.com/topic/14888-generating-pages-based-on-category_id/#findComment-59671 Share on other sites More sharing options...
john-formby Posted July 18, 2006 Author Share Posted July 18, 2006 EDIT: It has taken me all day, but I have sorted it :DThanks Quote Link to comment https://forums.phpfreaks.com/topic/14888-generating-pages-based-on-category_id/#findComment-59809 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.