Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

PHP Code for CSV export

Locked
arvind.acharya
Posts: 18
Joined: Tue Nov 26, 2013 9:14 am

PHP Code for CSV export

Unread post by arvind.acharya »

Hi,

I am trying to get csv export in Nubuilder pro from mysql table with selected criteria. I had used in Nubuilder 2.8 which had csv export option under php code. How can this be done in Nubuilder PRO?

Regards,

AA
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: PHP Code for CSV export

Unread post by admin »

AA,

Try running this as PHP Code..

Code: Select all


header('Content-Type: application/excel');
header('Content-Disposition: attachment; filename="Truck_Export.csv"');

$sql = "SELECT * FROM customer";
$qry = nuRunQuery($sql);


$fp = fopen('php://output', 'w');

$header = false;
while($obj = db_fetch_array($qry)){

	$size = count($obj)/2;
	for ($i = 0; $i < $size; $i++) {
	  unset($obj[$i]);
	}

	if($header == false) {
		$a       = array();
		foreach ($obj as $key => $value){
			$a[] = $key;
		}
		fputcsv($fp, $a);		
		$header = true;
	}

    fputcsv($fp, $obj);
}
fclose($fp);

Steven
arvind.acharya
Posts: 18
Joined: Tue Nov 26, 2013 9:14 am

Re: PHP Code for CSV export

Unread post by arvind.acharya »

Thanks this works.. :)
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: PHP Code for CSV export

Unread post by admin »

.
Locked