Nandini Posted May 7, 2009 Share Posted May 7, 2009 Hi I am exporting my database values in to text file while click on some link. I am getting a text file with the database values. But i am getting first line as a blank line. I have used trim() function. But no use. I want to export with out any blank lines. how can i do this? Here is my code: $text_dt=date("Y-m-d-H-i-s"); $file_name=$text_dt; header('Content-type: text/plain'); header('Content-Disposition: attachment; filename="'.$file_name.'.txt"'); $sql_rate=mysql_query("select * from lcdial_rates'"); while($row=mysql_fetch_array($sql_rate)) { echo trim($row['prefix']." ".trim($row['rate']); } pls help me out. Quote Link to comment https://forums.phpfreaks.com/topic/157231-solved-ignore-blank-lines-from-text-file/ Share on other sites More sharing options...
taith Posted May 7, 2009 Share Posted May 7, 2009 while($row=mysql_fetch_array($sql_rate)){ if(empty($row[prefix])||empty($row[rate])) continue; echo trim($row['prefix']." ".trim($row['rate']); } Quote Link to comment https://forums.phpfreaks.com/topic/157231-solved-ignore-blank-lines-from-text-file/#findComment-828463 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Why not just do that in the SQL? SELECT * FROM lcdial_rates WHERE prefix <> '' AND rate <> ''; Quote Link to comment https://forums.phpfreaks.com/topic/157231-solved-ignore-blank-lines-from-text-file/#findComment-828472 Share on other sites More sharing options...
ignace Posted May 7, 2009 Share Posted May 7, 2009 This function already exists: http://be.php.net/manual/en/function.file.php use as: <?php $fileLines = file('filename.txt', FILE_SKIP_EMPTY_LINES); ?> Quote Link to comment https://forums.phpfreaks.com/topic/157231-solved-ignore-blank-lines-from-text-file/#findComment-828477 Share on other sites More sharing options...
Nandini Posted May 8, 2009 Author Share Posted May 8, 2009 Thanx for ur reply. In database there no empty lines. So no need fire query as SELECT * FROM lcdial_rates WHERE prefix <> '' AND rate <> '' and check values are empty or not. And I am not reading a file. just i am exporting database values into text file. That means downloading a text file. I dont have empty line in database table. but i got first line as empty in text file. Quote Link to comment https://forums.phpfreaks.com/topic/157231-solved-ignore-blank-lines-from-text-file/#findComment-829254 Share on other sites More sharing options...
Nandini Posted May 8, 2009 Author Share Posted May 8, 2009 Hi all Problem was solved. This problem was occured about header content type. Thanx for all reply. Quote Link to comment https://forums.phpfreaks.com/topic/157231-solved-ignore-blank-lines-from-text-file/#findComment-829263 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.