hane Posted June 18, 2010 Share Posted June 18, 2010 Hi for some reason I just cant get my code to work. Please take a look and help me in the right direction. Here is my header builder for my export doc, $vExcelFileName is my problem: <?php require_once('includes/connect.php'); $adid=$_GET['adid']; mysql_select_db($database_A, $A); $query_ads = "SELECT * FROM ads JOIN company ON ads.companyid=company.companyid JOIN contact ON contact.companyid=ads.companyid WHERE adid=$adid"; $ads = mysql_query($query_ads, $A) or die(mysql_error()); $row_ads = mysql_fetch_assoc($ads); $totalRows_ads = mysql_num_rows($ads); $vExcelFileName=$row_ads['name'] . "ad-description-" . $row_ads['month'] ."-10" . ".doc"; header("Content-type: application/x-ms-download"); //#-- build header to download the excel file header("Content-Disposition: attachment; filename=$vExcelFileName"); header('Cache-Control: public'); ?> I'm sure its something silly that I'm not seeing and just need someone else to point it out Quote Link to comment Share on other sites More sharing options...
phpchamps Posted June 18, 2010 Share Posted June 18, 2010 whats the exact problem??? if you are not getting variable value.. try something like this header("Content-Disposition: attachment; filename=\"$outname\";\n\n"); Quote Link to comment Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 I have checked the code and it works, but when a name has spaces it falls apart how can I fix that Here is the problem: $vExcelFileName=$row_ads['name'] . "ad-description-" . $row_ads['month'] ."-10" . ".doc"; Quote Link to comment Share on other sites More sharing options...
phpchamps Posted June 18, 2010 Share Posted June 18, 2010 i run the code and its working fine at my machine.. even though... it has spaces in name... Quote Link to comment Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 When I run the code for Company lets say AIP Africa for June the file name is supposed to be: aipafrica-ad-description-jun-10.doc what I get is AIP Quote Link to comment Share on other sites More sharing options...
phpchamps Posted June 18, 2010 Share Posted June 18, 2010 and whts the filename do you get in that case???? Quote Link to comment Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 what I get is AIP Quote Link to comment Share on other sites More sharing options...
phpchamps Posted June 18, 2010 Share Posted June 18, 2010 are you sure your query is not returning multiple rows????? please post the result of your query.. Quote Link to comment Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 remember i call the info from my mysql database so I select AIP Africa from drop down then I select export and it exports all the info to a .doc file with the name populated with my the script in question Quote Link to comment Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 the easies would be to show you Go to http://www.hefty.co.za/agrisales/ Select Excaload from drop down submit then select PDF to see working example Select AIP Africa from drop down submit then select PDF to see problem Quote Link to comment Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 I fixed it with urlencode. Quote Link to comment Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 Please tell me if there is a better way Quote Link to comment Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 Think I found a better way: $n= $row_ads['name']; $na= preg_replace('/\s*/m','',$n); $vExcelFileName= $na ."-ad-description-" . $row_ads['month'] . "-10" . ".doc"; Quote Link to comment 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.