Jump to content

Category & Year Specification For Row


EternalSorrow

Recommended Posts

Greetings.  I am new to the board, and was curious if someone could answer my php coding problem.  I am attempting a large database which is will be accessed by visitors to my web page according to three page.  The first page will show a list of categories available to view, with a link to the next page.  The next page will show a list of years within that category, also with a link to those rows specified by both the category and year. 

 

An example would be:

 

click category link -> click year link -> arrive at row which applies to same category and year.

 

I am able to create the proper list of categories which, when clicked, will lead the visitor to the proper list of years related to that category.  However, using my current script I am unable to figure out how to specify the row to show only those which apply to the category and list.  I've scoured the internet, asked on other forums, and finally come on hands and needs for your assistance.  Any ideas?

 

category.php page:

 

<?php

mysql_connect(localhost,user,pw);
@mysql_select_db(db) or die( "Unable to select database");

$query = "SELECT DISTINCT category, category_id FROM `archives` WHERE `group` like '%inuyasha%' ORDER BY `category` ASC ";
$result = mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_array($result))
{
extract($row);

echo "<li><a href=\"inuyashayear.php?category_id=$category_id\">$category</A></li>";

}

?>

 

year.php page, which includes the code to display the rows (I sincerely apologize if the length is too long):

 

<?php

mysql_connect(localhost,user,pw);
@mysql_select_db(db) or die( "Unable to select database");

if (is_numeric($_GET["category_id"]))
{
$category_id = $_GET["category_id"];
}

$a = strip_tags(trim(htmlentities($_GET["a"], ENT_QUOTES)));

if (empty($a)) { $a = 'index'; }

switch ($a)
{

case 'index':

$select_year = mysql_query("SELECT DISTINCT `year`, category_id FROM `archives` WHERE `category_id` = '$category_id' ORDER BY `year` desc") or die (mysql_error());

while($row2=mysql_fetch_array($select_year))
{
extract ($row2);

$select_year_count = mysql_query("SELECT * FROM `archives` where `year`='$year' ORDER BY `year` ASC") or die (mysql_error());

echo "<li><a href=\"?a=show&year=$year\">$year</a></li>";

}

break;

case 'show':

$year2 = strip_tags(trim(htmlentities($_GET["year"], ENT_QUOTES)));

// Example Start Query
$query = "select DISTINCT year,  title, author, rating from `archives` WHERE `year`='$year2' AND category_id ='$category_id' order by year desc ";
$result = mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_array($result))
{
extract($row);

echo "<li>$title - $author - $rating</li>";;

}

}

?>

Link to comment
Share on other sites

click category link -> click year link -> arrive at row which applies to same category and year.

 

For example, with a link like select_year.php?category=12, that script should abstract the value of category

 

$category = $_GET['category'];

 

Then your year selector needs to generate links like do_next_thing.php?year=whatever&category=$category;

 

When do_next_thing.php executes. retrieve year and category

 

$category = $_GET['category'];

$year = $_GET['year'];

 

That should get you started

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.