Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Please help me solve a php question


Guest

Recommended Posts

I have the need for a script that will produce a all productslist for an dutch compare site www.kieskeurig.nl

 

I've tried serveral contributions. For example easy populate but i couldn't really modify the contri to my needs.

I've tried to wite a contri by myself (I'm really not a programmer)

I've used an other contri as input for a script that works for me.

If you run the code (just create a file in de root of your oscommerce install en run it) it will produce a html page with all the products on it.

 

I use the following code

<?php
// ********************************************************************************
****************************************
// Fantom. 
// Kieskeurig output file.
// just drop this file onto the admin folder and execute from your browser. That's All!
// Contact: [email protected]
// ********************************************************************************
****************************************
// configuration of the parameters
$separator  = '~';
$endofrow  = "<br>";
$products_tax_class_id = 4;

// Intialization of the file
require('includes/application_top.php');
$products_tax = tep_get_tax_rate($products_tax_class_id);

// Now lets perform the query
$qry = "select distinct c.categories_name, pd.products_name, pd.products_description, p.products_price, p.products_model, p.products_image, m.manufacturers_name" . 
 " from " . TABLE_PRODUCTS . " p, " . TABLE_CATEGORIES_DESCRIPTION . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m" . 
 " where p.products_id = pd.products_id and p.manufacturers_id = m.manufacturers_id and p.products_id = pc.products_id and pc.categories_id = c.categories_id AND c.language_id = '" . (int)$languages_id . "' and pd.language_id = '" . (int)$languages_id . "'" . 
 " order by trim(c.categories_name), m.manufacturers_name, trim(pd.products_name) asc";

$records = tep_db_query($qry);
$num_records = tep_db_num_rows($records);

// let?s do the loop	
$i = 0;			  
$table = mysql_fetch_array($records);
while ($table) {
$category1 = $table['categories_name'];
$manufacturer1 = $table['manufacturers_name'];

do {
$category = $table['categories_name'];
$manufacturer = $table['manufacturers_name'];
$product = $table['products_name'];
$model = $table['products_model'];
$price = $table['products_price'];
$price_with_tax = $currencies->display_price($price, $products_tax);

if ($category != $category1 || $manufacturer != $manufacturer1) {
break;
}

 echo $manufacturer1;
 echo $separator;
 echo $category1;
 echo $separator;
 echo $product;
 echo $separator;
 echo $model;
 echo $separator;
 echo $price_with_tax;
 echo $endofrow;

$i++;
 }	while ($table = mysql_fetch_array($records));
}
?>

This works fine to produce the list but i really need a popup that i can save the file locally to send it to a third party.

According to the tutorials that i've read i need the code below to create a popup that aloows me to save the file locally.

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=kieskeurig.txt");
header("Pragma: no-cache");
header("Expires: 0");
echo $variable met de text;
die();

When i put the code in the file i get erros like below

 

You can watch the script at work at www.navco.nl/kieskeurig.php

You can watch the script with the errors at www.navco.nl/kieskeurig2.php

 

the question is if a php guru can help me solve my issues.

 

thanks in advance

Link to comment
Share on other sites

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/navco/kieskeurig2.php:47) in /www/htdocs/navco/kieskeurig2.php on line 61

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/navco/kieskeurig2.php:47) in /www/htdocs/navco/kieskeurig2.php on line 62

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/navco/kieskeurig2.php:47) in /www/htdocs/navco/kieskeurig2.php on line 63

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/navco/kieskeurig2.php:47) in /www/htdocs/navco/kieskeurig2.php on line 64

 

Headers must be processed before any data can be outputted. i.e. place header() before your echo()'s.

 

I'm not a PHP expert, but I think your download code won't work.

 

 

Here's a new code suggestion for your page!

 

<?php
// ********************************************************************************

// Fantom.
// Kieskeurig output file.
// just drop this file onto the admin folder and execute from your browser. That's All!
// Contact: [email protected]
// ********************************************************************************

// configuration of the parameters
$separator = '~';
$endofrow = "<br>";
$products_tax_class_id = 4;

// Intialization of the file
require('includes/application_top.php');
$products_tax = tep_get_tax_rate($products_tax_class_id);

// Now lets perform the query
$qry = "select distinct c.categories_name, pd.products_name, pd.products_description, p.products_price, p.products_model, p.products_image, m.manufacturers_name" .
" from " . TABLE_PRODUCTS . " p, " . TABLE_CATEGORIES_DESCRIPTION . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m" .
" where p.products_id = pd.products_id and p.manufacturers_id = m.manufacturers_id and p.products_id = pc.products_id and pc.categories_id = c.categories_id AND c.language_id = '" . (int)$languages_id . "' and pd.language_id = '" . (int)$languages_id . "'" .
" order by trim(c.categories_name), m.manufacturers_name, trim(pd.products_name) asc";

$records = tep_db_query($qry);
$num_records = tep_db_num_rows($records);

// let?s do the loop
$i = 0;
$table = mysql_fetch_array($records);
while ($table) {
$category1 = $table['categories_name'];
$manufacturer1 = $table['manufacturers_name'];

do {
$category = $table['categories_name'];
$manufacturer = $table['manufacturers_name'];
$product = $table['products_name'];
$model = $table['products_model'];
$price = $table['products_price'];
$price_with_tax = $currencies->display_price($price, $products_tax);

if ($category != $category1 || $manufacturer != $manufacturer1) {
break;
}

//Puts all the content into $file_content
$file_content .= $manufacturer1;
$file_content .= $separator;
$file_content .= $category1;
$file_content .= $separator;
$file_content .= $product;
$file_content .= $separator;
$file_content .= $model;
$file_content .= $separator;
$file_content .= $price_with_tax;
$file_content .= $endofrow;

$i++;
} while ($table = mysql_fetch_array($records));

/**************************************/
//Here you need to create a script that writes the $file_content to a $fileName archive
//Remember to make the file writable
/**************************************/

/* Speed Limit in kB/s */
$speed = 10;

//Send the headers
header("Cache-control: private"); //This is for IE compatibility
header('Content-Description: File Transfer'); 
header('Content-Type: application/force-download');  //Forces the download
header('Content-Length: ' . filesize($fileName));  //Gets the size
header('Content-Disposition: attachment; filename=' . $fileName);

//If the file can't be open in read-mode, stop the script
if (!$file = fopen($fileName, 'r')) {
exit;
}

//This is used to limit d/l speed
while (!feof($file)) {
echo fread($file, $speed * 1024 * 8);
flush();
sleep(1);
}

//Closes the file
@fclose($file);

/******************************************************************/
//Here you must include some code to delete (destroy) your txtfile//
/******************************************************************/
?>

 

 

PS. This suggestion is for the download file!

Link to comment
Share on other sites

Thank you very much for your help.

I really appriciate it.

 

I understand that you are working with a temp file that is written in a temp dir.

 

This is not neccesary. All i need is that the output that is created in the $file_content variable is send directly to me in an text file.

 

What i's trying to achive now is to implement the following code:

<?php
// ********************************************************************************
// Fantom.
// Kieskeurig output file.
// just drop this file onto the admin folder and execute from your browser. That's All!
// Contact: [email protected]
// ********************************************************************************

require('includes/application_top.php');

// configuration of the parameters
$separator = '~';
$endofrow = "\n";
$products_tax_class_id = 4;
// End configuration

// Set tax variable
$products_tax = tep_get_tax_rate($products_tax_class_id);

// Now lets perform the query
$qry =	"select distinct c.categories_name, pd.products_name, pd.products_description, p.products_price, p.products_model, p.products_image, m.manufacturers_name" .
	" from " . TABLE_PRODUCTS . " p, " . TABLE_CATEGORIES_DESCRIPTION . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m" .
	" where p.products_id = pd.products_id and p.manufacturers_id = m.manufacturers_id and p.products_id = pc.products_id and pc.categories_id = c.categories_id AND c.language_id = '" . (int)$languages_id . "' and pd.language_id = '" . (int)$languages_id . "'" .
	" order by trim(c.categories_name), m.manufacturers_name, trim(pd.products_name) asc";

$records = tep_db_query($qry);
$num_records = tep_db_num_rows($records);

// let?s do the loop
$i = 0;
$table = mysql_fetch_array($records);

while ($table) {
$category1 = $table['categories_name'];
$manufacturer1 = $table['manufacturers_name'];

do {
	$category = $table['categories_name'];
	$manufacturer = $table['manufacturers_name'];
	$product = $table['products_name'];
	$model = $table['products_model'];
	$price = $table['products_price'];
	$price_with_tax = $currencies->display_price($price, $products_tax);

	if ($category != $category1 || $manufacturer != $manufacturer1) {
	break;
	}

	//Puts all the content into $file_content
	$file_content .= $manufacturer1;
	$file_content .= $separator;
	$file_content .= $category1;
	$file_content .= $separator;
	$file_content .= $product;
	$file_content .= $separator;
	$file_content .= $model;
	$file_content .= $separator;
	$file_content .= $price_with_tax;
	$file_content .= $endofrow;

	$i++;
	} while ($table = mysql_fetch_array($records));
}

//download the file
if ( $download == 'stream' ){

//Send the headers
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=kieskeurig.txt");
header("Pragma: no-cache");
header("Expires: 0");
echo $file_content;
die();
}
?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title>Kieskeurig feed file generator</title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
</head>
<a href="kieskeurig.php?download=stream"><b>Download Kieskeurig feed file</b></a><br>
</html>

 

Above code wil produce a page with a simple link on it.

When you click it the file will be downloaded.

 

I'm still having one problem.

At the end of every row a <CRLF> should be added.

The $endofrow = "\n"; does not work.

it only produces a CRLF whem i'm opening the file with wordpad.

The CRLF should also work when i'm openening the file with notepad.

 

Who has a suggestion to solve this issue?

 

thanks for the help.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...