php - Writing to CSV Issues -


the output file doesn't seem placing data csv

include_once ('database_connection.php');//including our db connection file if(isset($_get['keyword'])){//if url contains parameter "keyword"  $keyword =     trim($_get['keyword']) ;//remove  space $keyword = mysqli_real_escape_string($dbc, $keyword);//some validation  $query = "select topictitle,topicdescription topics topictitle '%$keyword%' or topicdescription '%$keyword%'"; //the sql query search word typed user .  $result = mysqli_query($dbc,$query);//run query if($result){//if query successfull  if(mysqli_affected_rows($dbc)!=0){//and if atleast 1 record found  while($row = mysqli_fetch_array($result,mysqli_assoc)){ //display 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 :"'.$_get['keyword'].'"';//no match found in database  }  } }else {  echo 'parameter missing in url';//if url invalid } 

the output file places except topicdescription.

instead of line :

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

use

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

also change $_get['topictitle'] , $_get['topicdescription'] $row['topictitle'] , $row['topicdescription']


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -