If this is your first visit, check our documentation. To post, register or login.
Forums / General Questions / General Questions / Building CSV list

Building CSV list

Started by familynow on 27 Sep 2012, 2:32 PM · Views: 1,779

Results 1 to 20 of 24
27 Sep 2012, 2:32 PM
#1
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Building CSV list

Hi.

I need to export a list in CSV and have product_id, _name & manufacturer_id, _name in the same list so I can cross reference with my suppliers list. I've done it before but it's been a while and can't seem to wrap my brain around it at the moment.

Thanks in advance

27 Sep 2012, 2:46 PM
#2
limitless avatar

limitless

Inactive

Join Date:
Jan 2012
Posts:
496
Plugin Contributions:
0

Re: Building CSV list

Get a decent SQL editor (HeidiSQL, SQL Workbench, etc) and you can query and export what you need.

Here is a query I use for exporting to csv format, you will need to modify just about everything, but should get you started in regards to the joins required, syntax, etc.

The first bits build out the csv header and default values (as they are static).

Hope the sort of helps?! If not, I can probably whip up the query in a bit.

If you want to dump the file to the local server, you need to finish the SELECT statement with INTO OUTFILE.

SELECT CONCAT(manufacturers.manufacturers_name, ' ', products_description.products_name)as "TITLE", CONCAT(CONCAT(CONCAT('<a href="http://www.xxxxxxxxxxxxxxxx.com/index.php?main_page=product_info&products_id=', products.products_id), 'target="_blank">', manufacturers.manufacturers_name, ' ', products_description.products_name, '</a>'),'<br>', products_description.products_description) as "DESCRIPTION",
'Factory New' as "CONDITION", '60' as "DURATION", products.products_quantity as "QUANTITY", '' as "STARTING BID", '' as "RESERVE PRICE", products.products_price as "BUY NOW PRICE", 'STORE-NAME' as "CATEGORY",
products.products_upc as "SKU", products.products_model as "NOTES", CONCAT("http://www.xxxxxxxxxxxxxxxxxx.com/images/",products.products_image) as "PICTURE 1", '' as "PICTURE 2", '' as "PICTURE 3",'' as "PICTURE 4",
'' as "PICTURE 5",'' as "PICTURE 6",'' as "PICTURE 7",'' as "PICTURE 8",'No' as "OVERNIGHT SHIPPING", '' as "OVERNIGHT COST", 'No' as "TWO DAY SHIPPING", '' as "TWO DAY COST", 'No' as "THREE DAY SHIPPING",
'' as "THREE DAY COST", 'Yes' as "GROUND SHIPPING", '' as "GROUND COST", 'Yes' as "FIRST CLASS SHIPPING", '' as "FIRST CLASS COST", 'Yes' as "PRIORITY SHIPPING", '' as "PRIORITY COST", '' as "OTHER SHIPPING",
'' as "OTHER COST", 'CO:2.9' as "SALES TAX RATES", 'No' as "REQUIRES FFL", '' as "SERIAL NUMBER", products.products_price as "FIXED PRICE", '' as "SHIPPING PROFILE ID", products.products_weight as "WEIGHT",
'1' as "WEIGHT UNIT"

FROM products
INNER JOIN products_description ON products_description.products_id = products.products_id
INNER JOIN product_extra_fields ON product_extra_fields.products_id = products_description.products_id
INNER JOIN products_to_categories ON products_to_categories.products_id = products_description.products_id AND products_to_categories.products_id = product_extra_fields.products_id AND products_to_categories.products_id = products.products_id
INNER JOIN categories ON categories.categories_id = products_to_categories.categories_id
INNER JOIN categories_description ON products_to_categories.categories_id = categories_description.categories_id
INNER JOIN manufacturers_info On products.manufacturers_id = manufacturers_info.manufacturers_id
INNER JOIN manufacturers On manufacturers_info.manufacturers_id = manufacturers.manufacturers_id
WHERE products.manufacturers_id = '68' AND products_quantity > 0 AND products_price > 25

27 Sep 2012, 3:18 PM
#3
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Building CSV list

Limitless:

Get a decent SQL editor (HeidiSQL, SQL Workbench, etc) and you can query and export what you need.
I was using phpmyadmin

Limitless:

Here is a query I use for exporting to csv format, you will need to modify just about everything, but should get you started in regards to the joins required, syntax, etc.

ouch! I think that actually hurt ;) I know very little about querying SQL unfortunately. What I did before(and conveniently forgot the specifics) in phpmyadmin I would select the desired fields and export to a spreadsheet(open text I think it was- I use LibreOffice) and then just sort/delete the columns and rows accordingly since I only need the few mentioned above.

I just can't seem to figure out which fields will allow me to have the one sI want in the same spreadsheet.

27 Sep 2012, 6:19 PM
#4
limitless avatar

limitless

Inactive

Join Date:
Jan 2012
Posts:
496
Plugin Contributions:
0

Re: Building CSV list

What fields are you looking for specifically?

product_id, product_name, manufacturer_id, and manufacturer_name??

27 Sep 2012, 6:26 PM
#5
limitless avatar

limitless

Inactive

Join Date:
Jan 2012
Posts:
496
Plugin Contributions:
0

Re: Building CSV list

SELECT products.products_id as "Product ID", products_description.products_name as "Product Name", manufacturers_info.manufacturers_id as "Manufacturers ID", manufacturers.manufacturers_name as "Manufacturers Name"

FROM products
INNER JOIN products_description ON products_description.products_id = products.products_id
INNER JOIN manufacturers_info On products.manufacturers_id = manufacturers_info.manufacturers_id
INNER JOIN manufacturers On manufacturers_info.manufacturers_id = manufacturers.manufacturers_id

27 Sep 2012, 6:36 PM
#6
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Building CSV list

Yes. Those and I forgot to mention product_model as well.

27 Sep 2012, 6:42 PM
#7
limitless avatar

limitless

Inactive

Join Date:
Jan 2012
Posts:
496
Plugin Contributions:
0

Re: Building CSV list

SELECT products.products_id as "Product ID", products_description.products_name as "Product Name", products.products_model as "Product Model", manufacturers_info.manufacturers_id as "Manufacturers ID", manufacturers.manufacturers_name as "Manufacturers Name"

FROM products
INNER JOIN products_description ON products_description.products_id = products.products_id
INNER JOIN manufacturers_info On products.manufacturers_id = manufacturers_info.manufacturers_id
INNER JOIN manufacturers On manufacturers_info.manufacturers_id = manufacturers.manufacturers_id

27 Sep 2012, 7:14 PM
#8
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Building CSV list

I hate to be a burden but is there any way you could tell me how to use this in phpmyadmin?

27 Sep 2012, 9:07 PM
#9
limitless avatar

limitless

Inactive

Join Date:
Jan 2012
Posts:
496
Plugin Contributions:
0

Re: Building CSV list

IIRC, there is a 'SQL' tab where you can paste in the query.

I dont use it, so that is from memory. Sorry.

27 Sep 2012, 9:18 PM
#10
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Building CSV list

That's what I thought but it only returns about 10 product- the list does have the desired feilds though. I think I know why this is happening but I don't know the workaround. All the products being listed are from the demo store. My actual store has a different table prefix(_wzc) because I'm currently on a shared hosting environment.

27 Sep 2012, 9:29 PM
#11
limitless avatar

limitless

Inactive

Join Date:
Jan 2012
Posts:
496
Plugin Contributions:
0

Re: Building CSV list

ok, then you either need to change the select statement or connect directly to the database and run the command on the zencart db not on the default db.

27 Sep 2012, 9:57 PM
#12
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Building CSV list

okay. So this is what I built from your example:

SELECT wzc_products.products_id as "Product ID", wzc_products_description.products_name as "Product Name", wzc_products.products_model as "Product Model", wzc_manufacturers_info.manufacturers_id as "Manufacturers ID", wzc_manufacturers.manufacturers_name as "Manufacturers Name"

FROM products
INNER JOIN wzc_products_description ON wzc_products_description.products_id = wzc_products.products_id
INNER JOIN wzc_manufacturers_info On wzc_products.manufacturers_id = wzc_manufacturers_info.manufacturers_id 
INNER JOIN wzc_manufacturers On wzc_manufacturers_info.manufacturers_id = wzc_manufacturers.manufacturers_id

I was getting an error "#1054 - Unknown column 'wzc_products.products_id' in 'field list' " but when I removed the ";" delimiter just below it accepted it. I hit go about 10 minutes ago and it's still working. Is it possible a query would take so long or did I do something wrong?!

27 Sep 2012, 10:03 PM
#13
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Building CSV list

yet if I browse the wzc_products
SELECT COUNT( * ) AS Rows , products_id
FROM wzc_products
GROUP BY products_id
ORDER BY products_id
LIMIT 0 , 30

I get 69 pages returned(I have approx. 2,100 products)

27 Sep 2012, 10:13 PM
#14
limitless avatar

limitless

Inactive

Join Date:
Jan 2012
Posts:
496
Plugin Contributions:
0

Re: Building CSV list

familynow:

okay. So this is what I built from your example:

SELECT wzc_products.products_id as "Product ID", wzc_products_description.products_name as "Product Name", wzc_products.products_model as "Product Model", wzc_manufacturers_info.manufacturers_id as "Manufacturers ID", wzc_manufacturers.manufacturers_name as "Manufacturers Name"

FROM products
INNER JOIN wzc_products_description ON wzc_products_description.products_id = wzc_products.products_id
INNER JOIN wzc_manufacturers_info On wzc_products.manufacturers_id = wzc_manufacturers_info.manufacturers_id
INNER JOIN wzc_manufacturers On wzc_manufacturers_info.manufacturers_id = wzc_manufacturers.manufacturers_id

> 
> I was getting an error "#1054 - Unknown column 'wzc_products.products_id' in 'field list' " but when I removed the ";" delimiter just below it accepted it. I hit go about 10 minutes ago and it's still working. Is it possible a query would take so long or did I do something wrong?!

I have 50k products and it returns all results in ~1 second.

Not sure which semicolon delimiter you are talking about?

I think you need to edit the 

from products to from wzc_products...
28 Sep 2012, 8:56 PM
#15
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Building CSV list

I kinda thought so...

At the bottom of the SQL tab there is a "delimiter" field and a semicolon in it by default. If I leave the semicolon I get the aformentioned error. If I remove it the page jsut times out(blank). I guess I'll have to try with something other than phpmyadmin.

28 Sep 2012, 9:36 PM
#16
limitless avatar

limitless

Inactive

Join Date:
Jan 2012
Posts:
496
Plugin Contributions:
0

Re: Building CSV list

I like heidisql (free) but you will have to add a mysql user/host to allow connection to your shared server from your PC.

29 Sep 2012, 2:49 PM
#17
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Building CSV list

I've been trying to connect using libreoffice base and just can't figure it out.

29 Sep 2012, 4:23 PM
#18
limitless avatar

limitless

Inactive

Join Date:
Jan 2012
Posts:
496
Plugin Contributions:
0

Re: Building CSV list

Do you have the MySQL odbc connector installed and configured?

If you do not configure your MySQL server to allow remote connections from your IP, you will not get access to your data (regardless of tool).

29 Sep 2012, 5:14 PM
#19
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Building CSV list

Yeah I thought of that. I'm not certain how to do that in a shared enviro. Do you think that might be a setting I could adjust in phpmyadmin?

29 Sep 2012, 5:26 PM
#20
limitless avatar

limitless

Inactive

Join Date:
Jan 2012
Posts:
496
Plugin Contributions:
0

Re: Building CSV list

Yes. You need to specify which hosts a user can connect from.

You will need your PC's IP address, you don't want to open it up to the world.