Php 编写CSV问题

Php 编写CSV问题,php,fwrite,Php,Fwrite,输出文件似乎没有将数据正确地放入CSV include_once ('database_connection.php');//Including our DB Connection file if(isset($_GET['keyword'])){//IF the url contains the parameter "keyword" $keyword = trim($_GET['keyword']) ;//Remove any extra space $keyword = mys

输出文件似乎没有将数据正确地放入CSV

include_once ('database_connection.php');//Including our DB Connection file
if(isset($_GET['keyword'])){//IF the url contains the parameter "keyword"
 $keyword =     trim($_GET['keyword']) ;//Remove any extra  space
$keyword = mysqli_real_escape_string($dbc, $keyword);//Some validation

$query = "select topictitle,topicdescription from topics where topictitle like '%$keyword%' or topicdescription like '%$keyword%'";
//The SQL Query that will search for the word typed by the user .

$result = mysqli_query($dbc,$query);//Run the Query
if($result){//If query successfull
 if(mysqli_affected_rows($dbc)!=0){//and if atleast one record is found
 while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){ //Display the record
 echo '<p> <b>'.$row['topictitle'].'</b> '.$row['topicdescription'].'</p>
 <input type="text" value="'.$_GET['keyword'].'" /><input type="text" value="'.$row['topicdescription'].'" />
 '   ;

                $numbre = fopen($_GET['keyword'].'.csv',"w");
                echo fwrite($numbre, "topictitle,topicdescription\r\n");
                echo fwrite($numbre, $_GET['topictitle'].",&".$_GET['topicdescription']);
                fclose($numbre);

 }
 }else {
 echo 'No Results for :"'.$_GET['keyword'].'"';//No Match found in the Database
 }

}
}else {
 echo 'Parameter Missing in the URL';//If URL is invalid
}
include_once('database_connection.php')//包括我们的数据库连接文件
if(isset($\u GET['keyword']){//如果url包含参数“keyword”
$keyword=trim($\u GET['keyword']);//删除任何额外空间
$keyword=mysqli\u real\u escape\u string($dbc,$keyword);//一些验证
$query=“从主题中选择topictitle、topicdescription,其中topictitle类似于“%$keyword%”或topicdescription类似于“%$keyword%””;
//将搜索用户键入的单词的SQL查询。
$result=mysqli_query($dbc,$query);//运行查询
if($result){//if查询成功
如果(mysqli_受影响的_行($dbc)!=0){//并且如果至少找到一条记录
而($row=mysqli\u fetch\u数组($result,mysqli\u ASSOC)){//显示记录
回显“”.$row['topictitle'.]”..$row['topicdescription'.]

' ; $numbre=fopen($_GET['keyword']..csv',“w”); echo-fwrite($numbre,“topictitle,topicdescription\r\n”); echo-fwrite($numbre,$_-GET['topictitle']..”和“$_-GET['topicdescription']); fclose($numbre); } }否则{ echo“没有结果:”。$\u GET['keyword'].'”;//在数据库中找不到匹配项 } } }否则{ echo“URL中缺少参数”;//如果URL无效 }

输出文件会放置除主题描述之外的所有内容。

而不是此行:

echo fwrite($numbre, "topictitle,topicdescription\r\n"); echo-fwrite($numbre,“topictitle,topicdescription\r\n”); 用这个 echo fwrite($numbre,$row['topictitle'.]”,“$row['topicdescription'.]”,“\r\n”);


同时将
$\u GET['topictitle']
$\u GET['topicdescription']
更改为
$row['topictitle']
$row['topicdescription']

echo-fwrite($numbre,$\u GET['topictitle'],&“$\u-GET['topicdescription]”)
您的意思是将数据库查询中的
$row[“topictitle”]
$row[“topicdescription”]
写入CSV而不是URL参数吗?

我想做的是,如果显示的结果显示topictitle和topicdescription的foo和bar,然后将它们写入CSV文件。确定。你看到伍夫莫的帖子了吗?他说了我的意思。行吗?谢谢行。我已经做了几个小时了,真不敢相信我错过了。 echo fwrite($numbre, $row['topictitle'] . "," . $row['topicdescription'] . "\r\n");