I'm having a query problem with my SQL. Basically the problem I'm having right now is, I store the cateogry types in the category_type table and then in the static_page_permission table I connect the category_type and the customer_type table together like the following:
insert into static_page_permission VALUES('1', 'customer_type', '2');
Which would link food (from category_type) and Customer (customer_type) to the static_page_permission table.
Let's say for category_type:
1 food YES
2 salad YES
3 fruit YES
4 gardens YES
customer_type:
1 Customer Active
2 Affiliate Active
--
DROP TABLE IF EXISTS `category_types`;
CREATE TABLE `category_types` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(155) NOT NULL default '',
`login` enum('yes','no') NOT NULL default 'yes',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `customer_type`;
CREATE TABLE `customer_type` (
`customer_typeid` int(11) NOT NULL auto_increment,
`type_name` varchar(128) NOT NULL default '',
`status` enum('Active','Inactive') NOT NULL default 'Active',
PRIMARY KEY (`customer_typeid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `static_page_permission`;
CREATE TABLE `static_page_permission` (
`typeid` int(11) NOT NULL default '0',
`table_name` varchar(25) NOT NULL default '',
`table_type` int(11) NOT NULL default '0',
KEY `typeid` (`typeid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
Ultimately, I need a way to query this and put it into checkboxes with a way to pass variables to say whether or not it is checked or not. I wrote a funciton that somewhat does that. Please help! If you have an easier way for me to retrieve this, by all means, let me know!
function page_list_customer_types($
ids = null)
{
$output = NULL;
// Sorting
@asort($ids);
$q = mysql_query("select * from customer_type where status='Active'");
for($i = 0; $row = mysql_fetch_assoc($q); ++$i) {
$checked = ($ids[$i] == $row['customer_typeid']) ? "CHECKED" : "";
$output .= "<input ".$checked." type=\"checkbox\" name=\"cust_type_".$i."\" value=\"".$row['customer_t
ypeid']."\
">".$row['
type_name'
]."<br />";
}
return $output;
}
// $ids is an array of the selected values... but that seems to not be working properly. Please help :)
Jacob