Forum Moderators: coopster
CREATE TABLE `discounts` (
`id` smallint(5) NOT NULL auto_increment,
`redeem` tinyint(3) NOT NULL,
`discount_title` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
`short_description` tinytext character set utf8 collate utf8_unicode_ci NOT NULL,
`eligibility` blob NOT NULL,
`url` varchar(100) character set utf8 collate utf8_unicode_ci default NULL,
`coupon_code` varchar(75) character set utf8 collate utf8_unicode_ci default NULL,
`start_date` datetime default NULL,
`end_date` datetime default NULL,
`long_description` text character set utf8 collate utf8_unicode_ci NOT NULL,
`logo` varchar(255) character set utf8 collate utf8_unicode_ci default NULL,
`business_name` varchar(75) character set utf8 collate utf8_unicode_ci NOT NULL,
`store_location_street` varchar(75) character set utf8 collate utf8_unicode_ci default NULL,
`store_location_city` varchar(75) character set utf8 collate utf8_unicode_ci default NULL,
`store_location_state` char(2) character set utf8 collate utf8_unicode_ci default NULL,
`store_location_zip` varchar(10) character set utf8 collate utf8_unicode_ci default NULL,
`categories` blob NOT NULL,
`level` tinyint(5) NOT NULL,
`active` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `level` (`level`,`active`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ;
--
-- Dumping data for table `discounts`
--
INSERT INTO `discounts` (`id`, `redeem`, `discount_title`, `short_description`, `eligibility`, `url`, `coupon_code`, `start_date`, `end_date`, `long_description`, `logo`, `business_name`, `store_location_street`, `store_location_city`, `store_location_state`, `store_location_zip`, `categories`, `level`, `active`) VALUES
(1, 0, '', 'Description', 0x4172726179, NULL, NULL, NULL, NULL, 'Long description', NULL, 'Business Name', NULL, NULL, NULL, NULL, 0x4172726179, 0, 0),
(2, 0, '', 'Description', 0x4172726179, NULL, NULL, NULL, NULL, 'Long description', NULL, 'Business Name', NULL, NULL, NULL, NULL, 0x4172726179, 0, 0),
(3, 0, '', 'Description', 0x4172726179, NULL, NULL, NULL, NULL, 'Descriptionzzz', NULL, 'Business Name', NULL, NULL, NULL, NULL, 0x4172726179, 0, 0),
(4, 0, '', 'Description', 0x4172726179, NULL, NULL, NULL, NULL, 'Descriptionzzz', NULL, 'Business Name', NULL, NULL, NULL, NULL, 0x4172726179, 0, 0),
(5, 0, '', 'Description', 0x4172726179, NULL, NULL, NULL, NULL, 'Long Description, son', NULL, 'Bidness Naym', NULL, NULL, NULL, NULL, 0x4172726179, 0, 0),
(6, 0, '', 'Description', 0x4172726179, NULL, NULL, NULL, NULL, 'Long Description, son', NULL, 'Bidness Naym', NULL, NULL, NULL, NULL, 0x4172726179, 0, 0),
(7, 0, '', 'Description', 0x4172726179, NULL, NULL, NULL, NULL, 'Long Description, son', NULL, 'Bidness Naym', NULL, NULL, NULL, NULL, 0x4172726179, 0, 0),
(8, 0, '', 'Description', 0x4172726179, NULL, NULL, NULL, NULL, 'Long Description, son', NULL, 'Bidness Naym', NULL, NULL, NULL, NULL, 0x4172726179, 0, 0),
(9, 0, '', 'Description', 0x4172726179, NULL, NULL, NULL, NULL, 'Long Description, son', NULL, 'Bidness Naym', NULL, NULL, NULL, NULL, 0x4172726179, 0, 0);
/*Name: fetch_category_discounts($cat_ID)
/*Desc: This function grabs the discounts a category contains when fed a valid cat_ID variable
/*
*/
function fetch_category_discounts($cat_ID) {
mysql_connect(SQL_HOST_NAME, SQL_USER_NAME, SQL_PASSWORD) or die(mysql_error());
mysql_select_db(SQL_DATABASE) or die(mysql_error());
$result = mysql_query("SELECT * FROM discounts, category_relations WHERE category_relations.member_of = '$cat_ID' AND category_relations.id = discounts.id")or die(mysql_error());
$aOutput = array();
while($row = mysql_fetch_assoc($result)){
$aOutput[] = $row;
}
return $aOutput;
} if(!empty($cat_ID)){
$category_name = fetch_category_name($cat_ID);
$paid_ads = fetch_category_paid_ads($cat_ID);
$discounts = fetch_category_discounts($cat_ID);
print_r($discounts);
$i = 0;
$paid_ads_count = count($paid_ads);
$discounts_count = count($discounts);
echo '<h1 class="category_name">'.$category_name.' <span class="small_font">('.$discounts_count.')</span></h1>';
if(!empty($paid_ads_count)){
$i = 0;
while($i < $paid_ads_count){
echo '<a href="'.$paid_ads[$i]['url'].'" target="_blank"><img src="'.$paid_ads[$i]['filename'].'"/></a>';
$i++;
}
}
if(!empty($discounts_count)){
$i = 0;
while($i < $discounts_count){
$expiration_date = $discounts[$i]['end_date'];
$expiration_date = date("m/d/y", $expiration_date);
echo '<li><span class="short_discount"><a href="index.php?discount_ID='.$discounts[$i]['id'].'&category_NAMEID='.$cat_ID.'">'.$discounts[$i][$i]['short_discount'].'<span class="expiration_date">Exp: '.$expiration_date.'</span></a></span></li>';
$i++;
}
}else{
echo '<li><a href="">No discounts currently in this category.</a></li>';
}
}elseif(!empty($discount_ID)){
$category_name = fetch_category_name($category_NAMEID);
$merchant_name = fetch_merchant_name($discount_ID);
echo '<h1 class="merchant_name">'.$merchant_name.' <a href="index.php?cat_ID='.$category_NAMEID.'" class="back_link">(<img src="img/external_link.gif"/>Return to '.$category_name.')</a></h1>';
$long_discount = fetch_detailed_discount($discount_ID);
echo $long_discount;
Array
(
[0] => Array
(
[id] => 1
[redeem] => 0
[discount_title] =>
[short_description] => Description
[eligibility] => Array
[url] =>
[coupon_code] =>
[start_date] =>
[end_date] =>
[long_description] => Long description
[logo] =>
[business_name] => Business Name
[store_location_street] =>
[store_location_city] =>
[store_location_state] =>
[store_location_zip] =>
[categories] => Array
[level] => 0
[active] => 0
[member_of] => 1
)
[1] => Array
(
[id] => 2
[redeem] => 0
[discount_title] =>
[short_description] => Description
[eligibility] => Array
[url] =>
[coupon_code] =>
[start_date] =>
[end_date] =>
[long_description] => Long description
[logo] =>
[business_name] => Business Name
[store_location_street] =>
[store_location_city] =>
[store_location_state] =>
[store_location_zip] =>
[categories] => Array
[level] => 0
[active] => 0
[member_of] => 1
)
[2] => Array
(
[id] => 7
[redeem] => 0
[discount_title] =>
[short_description] => Description
[eligibility] => Array
[url] =>
[coupon_code] =>
[start_date] =>
[end_date] =>
[long_description] => Long Description, son
[logo] =>
[business_name] => Bidness Naym
[store_location_street] =>
[store_location_city] =>
[store_location_state] =>
[store_location_zip] =>
[categories] => Array
[level] => 0
[active] => 0
[member_of] => 1
)
[3] => Array
(
[id] => 8
[redeem] => 0
[discount_title] =>
[short_description] => Description
[eligibility] => Array
[url] =>
[coupon_code] =>
[start_date] =>
[end_date] =>
[long_description] => Long Description, son
[logo] =>
[business_name] => Bidness Naym
[store_location_street] =>
[store_location_city] =>
[store_location_state] =>
[store_location_zip] =>
[categories] => Array
[level] => 0
[active] => 0
[member_of] => 1
)
[4] => Array
(
[id] => 9
[redeem] => 0
[discount_title] =>
[short_description] => Description
[eligibility] => Array
[url] =>
[coupon_code] =>
[start_date] =>
[end_date] =>
[long_description] => Long Description, son
[logo] =>
[business_name] => Bidness Naym
[store_location_street] =>
[store_location_city] =>
[store_location_state] =>
[store_location_zip] =>
[categories] => Array
[level] => 0
[active] => 0
[member_of] => 1
)
)