Hello, I am fairly new to PHP, having just started messing around with it, but I need to solve something and I would apreciate any help any of you could offer.
Here is my problem:
There's a hardware online store built using php/html and connected to a mysql database.
It has a search function that consists of three dropdown boxes, one for firm, the second for product type, and the third for subproduct.
What I want is to make those dropdown boxes interconected, so if I select something from the first list ( the firm list ) the second dropdown box will be RE-populated with only the types of products that that firm produces ( same connection between the second and third ).
As it is now, the dropdown boxes are populated by querries, like this one ( this is for the items that will be placed in the firm dropdown box ):
$sql_combo_firma="SELECT DISTINCT firme.ID, firme.denfirma
FROM firme, produse
WHERE ((produse.id_firma=firme.ID) AND (produse.afisare='-1'))
ORDER BY firme.denfirma ASC";
and this is for the product dropdown box:
$sql_combo_categorie="SELECT DISTINCT categorie.ID, categorie.dencategorie
FROM categorie, produse
WHERE ((produse.id_categorie=categorie.ID) AND (produse.afisare='-1'))
ORDER BY categorie.dencategorie ASC";
Then I proceed to execute the queries:
$rez_combo_firma = MYSQL_QUERY($sql_combo_firma) OR DIE (mysql_error());
$rez_combo_categorie = MYSQL_QUERY($sql_combo_categorie) OR DIE (mysql_error());
and I count how many rows the queries have:
$linii_firma = MYSQL_NUM_ROWS($rez_combo_firma);
$linii_categorie = MYSQL_NUM_ROWS($rez_combo_categorie);
then a proceed to populate the dropdown lists:
ECHO "<SELECT NAME=combo_firma
ID=combo_firma
STYLE='font-family: Arial;
FONT-STYLE: normal;
FONT-SIZE: 11;
COLOR: #000000;
BACKGROUND-COLOR:#FFFFFF;
BORDER-COLOR: Gray;'
>";
ECHO "<OPTION VALUE = 0> Oricare </option>";
FOR ($i=0; $i<$linii_firma; $i++)
{
$rez_firma_ID = MYSQL_RESULT ($rez_combo_firma,$i,'ID');
$rez_firma_denfirma = MYSQL_RESULT ($rez_combo_firma,$i,'denfirma');
ECHO "<OPTION VALUE = $rez_firma_ID> $rez_firma_denfirma
</OPTION>";
}
ECHO "</SELECT>";
and
ECHO "<SELECT NAME=combo_categorie
ID=combo_categorie
STYLE='font-family: Arial;
FONT-STYLE: normal;
FONT-SIZE: 11;
COLOR: #000000;
BACKGROUND-COLOR:#FFFFFF;
BORDER-COLOR: Gray;'
>";
ECHO "<OPTION VALUE = 0> Oricare </OPTION>";
FOR ($i=0; $i<$linii_categorie; $i++)
{
$rez_categorie_ID = MYSQL_RESULT ($rez_combo_categorie,$i,'ID');
$rez_categorie_dencategorie = MYSQL_RESULT ($rez_combo_categorie,$i,'dencategorie');
ECHO "<OPTION VALUE = $rez_categorie_ID > $rez_categorie_dencategorie </OPTION>";
}
ECHO "</SELECT>";
the page also has a submit button that will display all the results on another frame of the page:
ECHO " <INPUT TYPE = submit
NAME = buton_submit
STYLE= 'FONT-FAMILY: Arial;
FONT-WEIGHT: bold;
FONT-STYLE: normal;
FONT-SIZE: 12;
COLOR:#000000;
BACKGROUND-COLOR: #FFFFFF;
BORDER-COLOR: Gray;'
VALUE = ' : : : SEARCH : : : '>";
but I am confident that this button is not important ( the display works ok by the way, and the search works too, it's just that if you select a combination that has no resoults it will just say that there were no results. Like selecting a firm in the first box and a product in the second box that that firm dose not have. )
SO I want to make those three dropdown boxes interconected so if I select a firm in the first box, the second box will be repopulated only with the products that that firm has.
I thought about extracting the firm name ( denfirma ) and saving it in a variable and using that as a condition in the queries for the other dropdown lists. But that would not work since the queries would need to be re-executed for that to work. TO that end I thought about using the onchange event, but I don't know how to use that either.
I also searched via google for examples and several came, but they all needed addons, or other plugins to work, either they used ajax ( what ever that is ) or javascripts.
I want to know if there is any way to achieve these dynamicly linked dropdown lists without complicatted addons or classes, namelly just using php/html.
And if there isn't a way to do that I would apreciate any suggestions on how to do this because it is imperative that I solve this problem as soon as possible.