thommenl Posted June 10, 2022 Posted June 10, 2022 I have script <?php require('includes/application_top.php'); # Output headers so that the file is downloaded rather than displayed header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=data.csv'); # Create a file pointer connected to the output stream $output = fopen('php://output', 'w'); try { # SQL for products with products extra images $exportSQL = "SELECT c.categories_id, c.parent_id AS pi, cd.categories_name AS cn FROM categories c LEFT JOIN categories_description cd ON c.categories_id = cd.categories_id WHERE cd.language_id = 2"; $exportQuery = tep_db_query($exportSQL); if (tep_db_num_rows($exportQuery) > 1) { while ($exportList = tep_db_fetch_array($exportQuery)) { // print_r($exportList).PHP_EOL; // var_dump($exportList); fputcsv($output, $exportList, ";"); } } } catch (PDOException $e) { print "Error: " . $e->getMessage(); die(); } Now I need to add the function of replacing the parent's ID with the name of the category. I have tried many things but I am not familiar with osCommerce. Please help.
Jack_mcs Posted June 10, 2022 Posted June 10, 2022 I'm not sure I understand what you are trying to do but $exportList will just be an array of each category with the two ID's and the name. If you want to change one of those you will need to edit the array before saving it. Something like $exportList['pi'] = $exportList['cn']; fputcsv($output, $exportList, ";"); Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
thommenl Posted June 10, 2022 Author Posted June 10, 2022 I had while ($exportList = tep_db_fetch_array($exportQuery)) { while ($exportList1 = tep_db_fetch_array($exportQuery1)) { if ($exportList['pi'] == $exportList1['categories_id']) { $exportList['pi'] = $exportList1['cn']; // break; } } // print_r($exportList).PHP_EOL; // var_dump($exportList); fputcsv($output, $exportList, ";"); } but the code only worked for the first cycle of the outer loop.
Jack_mcs Posted June 11, 2022 Posted June 11, 2022 So you are trying to get all of the categories? If so, use the tep_get_categories function. You can duplicate it and change what details it returns. Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
Recommended Posts
Archived
This topic is now archived and is closed to further replies.