無論何時使用PHP導出CSV文件,我都會遇到問題。我有一個像使用CSV文件進行字符轉換
SELECT `interest_id`,`interest_name`,`interested_user_id` FROM `interest_list` WHERE `interest_name` LIKE '%fashion%'
但每當一個MySQL查詢我試圖通過利用上述MySQL查詢導出一個PHP文件,然後我查詢轉向
SELECT `interest_id`,`interest_name`,`interested_user_id` FROM `interest_list` WHERE `interest_name` LIKE 'úshion%'
,使其返回沒有記錄。 請告訴我如何解決這個問題。 在出口文件,我這樣寫代碼:
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen('php://output', 'w');
//executed code
fputcsv($output, $blankArray);
現在,請幫助我。
其實,我使查詢在一個文件中,如:
$search_sql = "SELECT `interest_id`,`interest_name`,`interested_user_id` FROM `interest_list`";
if(isset($_REQUEST['search_user_btn'])){
if($_REQUEST['search_intr'] != '')
$search_sql .= " WHERE `interest_name` LIKE '%".$_REQUEST['search_intr']."%' ";
}
然後在同一個文件中我寫的一樣:
<a href="export.php?report=interest&qur=<?php echo $search_sql; ?>"><button>Export to CSV</button></a>
終於在export.php
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen('php://output', 'w');
我想獲得$ _REQUEST ['qur']的值。但無法獲得$ _REQUEST ['qur']的原始值。
我想現在它是有道理的。 請幫助....
你如何確定查詢已經改變?請顯示您使用的確切代碼。 – deceze 2012-04-24 07:48:01
將代碼顯示在生成SQL的位置並執行它會更有幫助。 – 2012-04-24 07:49:20
請再次看到上面的問題,我修改了。 – John 2012-04-24 07:52:55