0

出力ファイルがデータを 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
}

出力ファイルには、トピックの説明を除くすべてが配置されます。

4

2 に答える 2

1

この行の代わりに:

echo fwrite($numbre, "topictitle,topicdescription\r\n");

これを使って

echo fwrite($numbre, $row['topictitle'] . "," . $row['topicdescription'] . "\r\n");

また$_GET['topictitle']、 と$_GET['topicdescription']$row['topictitle']とに変更します$row['topicdescription']

于 2013-08-10T06:40:16.370 に答える
0

その行ではURLパラメータではなく、DBクエリからCSVにandecho fwrite($numbre, $_GET['topictitle'].",&".$_GET['topicdescription']);を書くということですか?$row["topictitle"]$row["topicdescription"]

于 2013-08-10T06:41:01.503 に答える