Jump to content


Photo

Generating pages based on category_id?


  • Please log in to reply
2 replies to this topic

#1 john-formby

john-formby
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts
  • LocationMahe, Seychelles

Posted 17 July 2006 - 09:46 PM

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:

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;


I have created a page for every menu option which contains the following:

<?php
include("common/header1.php");
?>

</head>

<body onload="initialiseMenu();">

<?
include("common/header2.php");
?> 
               <div id="maincol"><h1>Graphics - Advice Forums</h1>

<?php

include "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");
?>

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:

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


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.

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

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 Links

I 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
"I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image." ~ Stephen Hawking

#2 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 17 July 2006 - 10:09 PM

Is it just me, or would it be WAY easier just to use the $_GET method, and have something like:

page.php?link=1245

Where 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.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#3 john-formby

john-formby
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts
  • LocationMahe, Seychelles

Posted 18 July 2006 - 06:30 AM

EDIT: It has taken me all day, but I have sorted it :D

Thanks

"I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image." ~ Stephen Hawking




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users