<?PHP // Caleb Warts // Database To Froogle Tab File
// Constants // Database
define('database', 'hillcrestjewelers', true);
define('table', 'jewelery', true);
define('username', 'hcjewel', true);
define('password', 'SPark11ng', true);
define('file', '/home/hcjewel/public_html/froogle/froogle.txt', true);
// Connect // Database
$link		=	mysql_connect('localhost', username, password);
$query		=	"SELECT * FROM `jewelery` WHERE `status` != 'sold' AND `status` != 'returned';";
mysql_select_db(database, $link);
$string		=	"brand\ttitle\tcondition\tdescription\texpiration_date\tid\timage_link\tlink\tprice\tproduct_type\tapparel_type\n";
if(file_exists(file)){ unlink(file); };
$filesystem	=	fopen(file, 'w+') or die("file not found");
//setup vars
$type		=	"Jewelery";
$url		=	"http://hillcrestjewelers.com/searchb.php?number=";
$exe		=	".jpg";
$image		=	"http://www.hillcrestjewelers.com/jewelery/";
$tab		=	"\t";
$brand		=	"Hillcrest Jewelers";
$data_time	=	mysql_query("SELECT DATE_ADD(CURDATE(), INTERVAL 31 DAY);");
$date		=	mysql_fetch_array($data_time);
$data		=	mysql_query($query, $link);
while ($row = mysql_fetch_array($data, MYSQL_ASSOC)) {
	$string		=	$string	.	$brand															.	$tab;
	$string		=	$string	.	$row['metel'] . " " . $row['cstone'] . " " . $row['type']	. " " . $row['cstone'] . " " . $row['style']	.	$tab;
	$string		=	$string	.	"New"															.	$tab;
	$string		=	$string	.	$row['metel'] . " " . $row['cweight'] . " " . $row['ccolor'] . " " . $row['cshape'] . " " . $row['cstone'] . " " . $row['style']	. " " . $row['sweight'] . " " . $row['scolor'] . " " . $row['sshape']	. $tab;
	$string		=	$string	.	$date[0]														.	$tab;
	$string		=	$string	.	$row['itemnumber']												.	$tab;
	$string		=	$string	.	$image . $row['itemnumber'] . $exe								.	$tab;
	$string		=	$string	.	$url . $row['itemnumber']										.	$tab;
	$string		=	$string	.	$row['retail']													.	$tab;
	$string		=	$string	.	"product"														.	$tab;
	$string		=	$string .	"Jewelery";
	$string		=	$string	.	"\r\n";
};
	
fwrite($filesystem, $string);
fclose($filesystem);

echo	"IT WORKED";
?>
