I have a table called ClassCodeTypes and a table called OIIItems. Tables are INNODB/MySQL
When users add a record to OIIItem, they must choose a ClassCodeType (CCTID is a foreign key in the OIIItem table). Depending on which CCT the user chooses, my company would like to show only certain fields on the addItem form (For example, a user chooses a fastener class code and the form displays weight, stocked min/max, etc, but if they choose a document class code, the form does not need a weight or stocked min/max so they are not displayed).
Right now I have an ENUM('Y', 'N') field in ClassCodeType for each field in OIIItems, so my PHP scripts can choose to display a field or not on the form.
---
Is there a way to automatically have all of the fields in OIIItems as a ENUM field in ClassCodeTypes (in case a field is added to OIIItems later on)
What is the best way to iterate through these columns using php?
This is what I'm doing for now
When users add a record to OIIItem, they must choose a ClassCodeType (CCTID is a foreign key in the OIIItem table). Depending on which CCT the user chooses, my company would like to show only certain fields on the addItem form (For example, a user chooses a fastener class code and the form displays weight, stocked min/max, etc, but if they choose a document class code, the form does not need a weight or stocked min/max so they are not displayed).
Right now I have an ENUM('Y', 'N') field in ClassCodeType for each field in OIIItems, so my PHP scripts can choose to display a field or not on the form.
---
Is there a way to automatically have all of the fields in OIIItems as a ENUM field in ClassCodeTypes (in case a field is added to OIIItems later on)
What is the best way to iterate through these columns using php?
This is what I'm doing for now
Code:
$query="SHOW COLUMNS FROM ClassCodeTypes WHERE Field LIKE 'required%' OR Field LIKE 'show%'";
$result = safe_query($query);
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
$FieldName = $row['Field'];
if ($_GET["$FieldName"] == "") {
$$FieldName = "N";
} else {
$$FieldName = "Y";
}
}
}