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>";;
}
}
?>