|
|
#1 (permalink) |
|
Registered User
Join Date: Oct 2002
Posts: 17
|
PHP / mySQL help... queries
i'm writing a free-for-all style link management system for my website. What i'm working on right now is adding links to the system. I can already add Catagories and subCatagories. On the add a link page I have 2 dropdown boxes. One of them displays main catagories, the other displays subcatagories. What I want to do is either
1: only display subcatagories that go with the main catagory selected in the main catagory dropdown box or 2: Do away with the main dropdown box and use an SQL query to determine which subCats go with which main cat. and display is something like MainCat subCat Bit Torrent - Trackers Bit Torrent - Clients the only problem is that I need to pass along several variables about which catagory you've selected and as far as I know / can remember you can only have one value="whatever" tags inside of a <option> tag. Am i wrong or how should i go about doing this? If anyone wants to see code / db structure just leme know and i'll show it to ya... www.napjunk.net/links/links.php edit 2: fixed that bug...back to my main question EDIT by greffov: removed some obscene language from the title Last edited by Monkee of evil; 01-22-2004 at 12:02 PM. |
|
|
|
|
|
#2 (permalink) |
|
Da House Nerd
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
|
IE only supports groups from version 6 I think. Mozilla however supports it like it should (it's a standard)
Example of optgroup: Code:
<FORM METHOD="post" ACTION="bestemming"> <SELECT NAME="browser"> <OPTION VALUE="xx">Choose a browser</OPTION> <OPTGROUP LABEL="Microsoft Internet Explorer"> <OPTION VALUE="msie3">Microsoft Internet Explorer 3</OPTION> ... </OPTGROUP> <OPTGROUP LABEL="Mozilla"> <OPTION VALUE="moz1">Mozilla 1</OPTION> </OPTGROUP> <OPTGROUP LABEL="Netscape Navigator"> <OPTION VALUE="nn3">Netscape Navigator 3</OPTION> ... </OPTGROUP> <OPTGROUP LABEL="Opera"> <OPTION VALUE="op3">Opera 3</OPTION> ... </OPTGROUP> <OPTION VALUE="different">Different browser</OPTION> </SELECT> </FORM> Code:
<OPTGROUP LABEL="Netscape Navigator"> <OPTION LABEL="3" VALUE="nn3">Netscape Navigator 3</OPTION> <OPTION LABEL="4" VALUE="nn4">Netscape Navigator 4</OPTION> <OPTION LABEL="6" VALUE="nn6">Netscape Navigator 6</OPTION> <OPTION LABEL="7" VALUE="nn7">Netscape Navigator 7</OPTION> </OPTGROUP> To get all results at once from the database assuming you have a table named groups and a subgroup table, where subgroups has a primary key contraint on the groups table you can simply get a full list in a statement like this: Code:
SELECT *
FROM groups, subgroups
WHERE subgroups.groupid = groups.id
ORDER BY groups.name, subgroups.name
__________________
Linux virusscanner detected a virus: Windows 95 ... delete [Y/n] y ~ ~ :wq |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Oct 2002
Posts: 17
|
this is the db structure i have right now...could you elaborate a little on how i pull items from more than one table in one query? I'm relatively new to sql.
TABLE: link_cats_main cid - int(11) - Catagory ID, primary key ctitle varchar(255) - Catagory Title TABLE: link_cats_sub scid - int(11) - subcataory ID, primary key owner_cat int(11) - owner catagory, foriegn key to cid in link_cats_main c_title (varchar255) - catagory title. Table: link_links lid - int(11) - Link ID, primary key ltitle - varchar(255) - Title for the link lurl - varchar(255) - url lcount - int(11) - number of times the link has been clicked lmcat - int(11) - link main catagory, the MAIN catagory in which this link belongs lscat - int(11) - link subcatagory, same as above except for the subcat. |
|
|
|
|
|
#4 (permalink) |
|
Da House Nerd
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
|
SELECT link_cats_main.*, link_cats_sub.scid AS subid, link_cats_sub.c_title AS subtitle, link_links.lid AS linkid, link_links.ltitle AS linktitle, link_links.lurl AS linkurl FROM link_cats_main, link_cats_sub, link_links WHERE link_cats_main.cid = link_cats_sub.owner_cat AND link_cats_sub.scid = link_links.lscat
note that lmcat is not needed, and causes overhead (it needs to be assured lscat is a child of lmcat). Once can calculate the links of a category using the subcat too. basic idea: create a cartesian product of the three tables (FROM link_cats_main, link_cats_sub, link_links) and remove all rows that do not match your foreign key relation (the WHERE relation)
__________________
Linux virusscanner detected a virus: Windows 95 ... delete [Y/n] y ~ ~ :wq |
|
|
|
|
|
#5 (permalink) | |
|
Registered User
Join Date: Oct 2002
Posts: 17
|
Quote:
|
|
|
|
|
|
|
#7 (permalink) | |
|
Registered User
Join Date: Oct 2002
Posts: 17
|
Quote:
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|