EternalSorrow Posted March 3, 2008 Share Posted March 3, 2008 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>";; } } ?> Quote Link to comment Share on other sites More sharing options...
EternalSorrow Posted March 4, 2008 Author Share Posted March 4, 2008 bumpety Quote Link to comment Share on other sites More sharing options...
EternalSorrow Posted March 4, 2008 Author Share Posted March 4, 2008 bump again...going on the fourth time... Quote Link to comment Share on other sites More sharing options...
EternalSorrow Posted March 5, 2008 Author Share Posted March 5, 2008 bump...anyone? Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 5, 2008 Share Posted March 5, 2008 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 Quote Link to comment Share on other sites More sharing options...
EternalSorrow Posted March 5, 2008 Author Share Posted March 5, 2008 Thanks for the great explanation! That definitely cleared up some of my questions and confusions! Quote Link to comment 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.