Page 1 of 1

listing categories and subcategories in the same page.

Posted: Tue Nov 25, 2003 11:37 am
by jive
Hello folks,



The web application that I am working on has two tables: ac_type and ac_description basically ac_type is a category list of aircraft types and ac_description is like a subcategory list (of actual airplanes listed under that category) I have two pages:



actype.php:



This page lists the aircraft categorys and upon clicking the category It will take you to the next page (aircraftlist.php)

Code: Select all

//connect to the database

include("connect.php");

//query for a aircraft type table for a aircraft type list

$actypelist = mysql_query('SELECT ID, type, actype_num FROM ac_type ORDER BY actype_num ASC');

//create the chapterlist array using the while loop

while($actype = mysql_fetch_array($actypelist)) {

$id = $actype['ID'];

$type = $actype['type'];

$actype_num = $actype['actype_num'];

//display the chapterlist with links passing a url parameter

echo("<a href='aircraftlist.php?typeID=$id'>$type</a><br>");

}




aircraftlist.php


Code: Select all

include ('connect.php');

 

//query chapters and topics db to display the chapter/topic text

$typeID = $_GET['typeID'];

$aircraftlist = mysql_query("SELECT type, ac_description.ID AS ac_description_ID, ac_name, description_order

                         FROM ac_type, ac_description

                         WHERE actype_ID = ac_type.ID AND

                         actype_ID = $typeID ORDER BY description_order ASC " ) or die(mysql_error());

//create the topic array in the while loop

echo("<h3>Manage which Aircraft</h3>");

while($aircraft = mysql_fetch_array($aircraftlist)) {

$type = $aircraft['type'];

$ac_name = $aircraft['ac_name'];

$ac_desc_ID = $aircraft['ac_description_ID'];

$typeID = $aircraft['actype_ID'];

$description_order = $aircraft['description_order'];

 

echo("<table width='350' align='center' border='0' cellpadding='5'><tr>

<td width='5%'>$description_order</td>

<td width='85%'><a href='aircraftdetails.php?ac_desc_ID=$ac_desc_ID'>$ac_name</a></td>

<td width='10%'><a href='newac_edit.php?ac_descID=$ac_desc_ID&type=$type'>Edit</a></td>

<td width='10%'><a href='newac_del.php?ac_descID=$ac_desc&type=$type'>Delete</a></td>

</tr>

</table>");

}

echo("<table width='350' align='center' border='0' cellpadding='5'><tr>

<td width='70%' colspan='2'></td><td width='30%' colspan='2' align='right'><a href='newac_add.php'>Add new aircraft</a></td>

</tr></table>");


You can check it out right here:

http://www.ectaviation.com/aircraftsales/actype.php



my question is how do I create a page that list the aircraft (subcategorys) underneath the aircraft types (categories) all in one page instead of two seperate pages like I have? I want it l like this:



category1

subcategory1

subcategory2

subcatgoy3



category2

subcategory1

subcategory2

subcategory3



I hope I made this clear....

Posted: Tue Nov 25, 2003 8:55 pm
by bionicdonkey
execute the subcategory query inside the category loop. the subcategory table sould have a foreign key to identify which category it belongs to.

Posted: Tue Nov 25, 2003 9:03 pm
by jive
this is what I'm having difficulty in. Can you give me a coding example?