Jump to content

PHP Export to CSV Issue


jarvis

Recommended Posts

Hi,

 

Am having a total brain melt down on a php/mysql export script. I've a table wp_bp_xprofile_data with this sort of layout:

ID

field_id

user_id

value

 

It shows data like so:

id | field_id | user_id | value

1 | 1 | 1| John Smith

2 | 2 | 1 |john@smith.com

3 | 3 | 1 |23 arcacia avenue

4 | 1 | 2 |Fred Smith

5 | 2 | 2 |fred@smith.com

6 | 3 | 2 |999 lets be avenue

 

 

field_id joins to another table wp_bp_xprofile_fields, where it has

id

name

This shows data like so:

id | name

1 | Name

2 | Email

3 | Address

 

What I need to do, is export the data to a csv so the CSV will then show:

 

Name | Email | Address

John Smith | john@smith.com | 23 arcacia avenue

Fred Smith | fred@smith.com | 999 lets be avenue

 

However, mine keeps coming back

Name | Email | Address

John Smith

john@smith.com

23 arcacia avenue

Fred Smith

fred@smith.com

999 lets be avenue

 

Here's my code:

header ("Content-Disposition:\"inline; filename=export.csv");

header ("Content-type: text/csv\"");

 

$query = "SELECT VALUE FROM `wp_bp_xprofile_data` ORDER BY `wp_bp_xprofile_data`.`user_id` ASC";

$result = mysql_query($query) or die("Query failed : " . mysql_error());

 

echo "email,telephone,county,town,add 2,add 1,company name,name,acc type,date joined,country\r\n"; //header

 

while($row = mysql_fetch_row($result)){

echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11]\r\n"; //data

 

echo "$row[]\r\n"; //data

}

[code=php:0]

Where am I going wrong?

 

TIA

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.