Jump to content

MYSQL to CSV Exporting problem...


tonynoriega

Recommended Posts

i almost got this...but cant seem to figure out why its only showing one record.

the query uses the dates selected by the user to query the records, when they hit the submit button, it generates the CSV file, but only displays the first record of the query...

i have tried putting the output of the CSV file in various locations, but what that does is immediately prompt for downloading of the file before the user can select dates, thus no records appear....

 

anyone???

 

function leadstablesearchexport_display_addon() { 

	global $config, $conn, $jscript;
		require_once($config['basepath'] . '/include/misc.inc.php');

		$misc = new misc();
		$jscript.='<script type="text/javascript" language="javascript" src="'.$config['baseurl'].'/addons/builderreport/CalendarPopup.js"></script>'."\r\n";
		$jscript.='<script type="text/javascript" language="javascript">var cal = new CalendarPopup(); </script>'."\r\n";
		$jscript.='<script type="text/javascript" src="'.$config['baseurl'].'/addons/builderreport/form_validation.js"></script>'."\r\n";


		$date1 = $_POST['date1'];
		$date2 = $_POST['date2'];
		$community = $_POST['community'];
		$nhm_associate = $_POST['nhm_associate'];

		$new_date2 = strtotime("$date2");
		$new_date1 = strtotime("$date1");
		$end_date = date("l", $new_date2);



		$display .='<form name="registration" action="index.php?action=addon_leadstable_displaysearchexport" method="post" onSubmit="return validateSelect()">
					<table style="width:750px;">
						<tr>
							<td style="text-align:right; vertical-align:bottom;">
								<input type="text" name="date1" value="" size=15 id="date1">
								<a href="#" onclick="cal.select(document.forms[\'registration\'].date1,\'anchor1\',\'yyyy-MM-dd\'); return false;" name="anchor1" id="anchor1"><img src="http://www.mydomain.com/images/calPick.jpg"></a>
							</td>
							<td style="text-align:right; vertical-align:bottom;">
								<input type="text" name="date2" value="" size=15 id="date2"> 
								<a href="#" onclick="cal.select(document.forms[\'registration\'].date2,\'anchor2\',\'yyyy-MM-dd\'); return false;" name="anchor2" id="anchor2"><img src="http://www.mydomain.com/images/calPick.jpg"></a>
							</td>
							<td style="text-align:right; vertical-align:bottom;">
								<select name="nhm_associate" id="nhm_associate">
									<option selected>NHM Associate</option>
								</select>
							</td>
							<td style="text-align:right;">
								<input type="submit" name="submit" value="Go" class="button">
							</td>
						</tr>
					</table><br /></form>';


//NEW REGISTRATION DISPLAY
			@ob_start(); 
			$content_file = ""; 
			$content_file .= "Lead Date,First Name,Last Name,Lead Type,Agent Name,Agent Co,Builder Remarks\r\n"; 
			$sql = 'SELECT * FROM registration_table WHERE lead_date BETWEEN \''. $date1 . '\' AND \'' . $date2 . '\' AND nhm_associate=\'' . $nhm_associate . '\' ORDER BY lead_date';


			$recordSet = $conn->Execute($sql);


			if ($recordSet === false) {
			$misc->log_error($sql);
			}

			while (!$recordSet->EOF) {

			$content_file .= $reg_lead_date = $recordSet->UserTimeStamp($recordSet->fields['lead_date'],'M j') 
							. ',' . $reg_fname = $misc->make_db_unsafe ($recordSet->fields['fname'])
							. ',' . $reg_lname = $misc->make_db_unsafe ($recordSet->fields['lname'])
							. ',' . $reg_prospect = $misc->make_db_unsafe ($recordSet->fields['lead_type'])
							. ',' . $reg_agent_name = $misc->make_db_unsafe ($recordSet->fields['agent_name']) 
							. ',' . $reg_agent_company = $misc->make_db_unsafe ($recordSet->fields['agent_company'])
							. ',' . $reg_builder_remarks = $misc->make_db_unsafe ($recordSet->fields['builder_remarks'])
							. '\r\n'; 

		$recordSet->MoveNext();
		$output_file = 'leads.csv';
			@ob_end_clean();
			@ini_set('zlib.output_compression', 'Off');
			header('Pragma: public');
			header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
			header('Cache-Control: no-store, no-cache, must-revalidate');
			header('Cache-Control: pre-check=0, post-check=0, max-age=0');
			header('Content-Transfer-Encoding: none');
			//This should work for IE & Opera
			header('Content-Type: application/octetstream; name="' . $output_file . '"');
			//This should work for the rest
			header('Content-Type: application/octet-stream; name="' . $output_file . '"');
			header('Content-Disposition: inline; filename="' . $output_file . '"');
			echo $content_file;
			exit(); 
		}

return $display;
}

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.