Thoughts Just4Qyx..."Live each day like it's your last..."
Just4Qyx
read my profile
sign my guestbook

Visit Just4Qyx's Xanga Site!

Name: Henry
Location: New York City, New York, United States


Interests: Dance2XS, Film, Bball, Ultimate, Blading, SC
Expertise: Professional Dancer/Web & Application Systems Developer
Occupation: Artist
Industry: Entertainment


Message: message me
Website: visit my website


Member Since: 8/21/2002

SubscriptionsSites I Read

Groups Blogrings
LIALC Salt n Light
previous - random - next

Dance2XS Family
previous - random - next

EverybodyDance!!!
previous - random - next


Posting Calendar

|<< oldest | newest >>|
view all weblog archives

Get Involved!

Suggest a link

Recommend to friend

Create a site


Tuesday, October 25, 2011

PHP Header Override Priority

http://php.net/manual/en/function.session-start.php

Just make sure the session_start() directive is processed before any other statements that modify the content headers.

https://bugs.php.net/bug.php?id=50276

Header directives (mod_header) are processed just before the response is sent to the network (and after any content generator like PHP)

 

So after a frustrating hour of debugging & research, here's what will save people lots of valuable time:

1. Setting cache headers in PHP using header() must occur AFTER the PHP session_start() directive or else they will be overridden with default Cache Headers.

2. Setting cache headers in PHP using header() will be overridden if identical headers are set either in httpd.conf or .htaccess.

 

Some additional helpful info:

PHP session_start() invokes session_cache_limiter() which sends default Cache headers http://php.net/manual/en/function.session-cache-limiter.php


Thursday, October 13, 2011

PHP: array_diff()

wow... another nice find. Such a time saver.  Two finds in one day!

http://php.net/manual/en/function.array-diff.php


MySQL: ON DUPLICATE KEY UPDATE

MySQL: INSERT...ON DUPLICATE KEY UPDATE

Pretty handy...

http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html


Tuesday, June 16, 2009

Exporting DataTable to Excel

.NET C#

TIPS:
1.
I decided to try and programmatically store the SqlDataSource control of my Gridview into a DataTable.  This way I could save a call to the database, and also guarantee that whatever data I was exporting would be the same data the GridView was displaying!

Solution: OnRowDataBound Gridview event.
e.Row.DataItem exposes the data held in the control as a DataView, then use dv.ToTable(). I store this into session.

2.
For the Button OnClick event, I call 2 methods, one to modify the DataTable to my liking (remove or rename columns, etc.), another to actually export the DataTable in session to my response stream.

After iterating the DataTable and converting it to CSV format using a StringBuilder variable (plenty of algorithms to do this if  you google), I write the data to the Response stream like so:

response.Clear();
response.ContentType = "application/vnd.ms-excel";
response.Charset = "";
response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}.csv", FileName));
response.Write(sb.ToString());
response.Flush();
response.End();


Debug Timewaster #1

http://stackoverflow.com/questions/679070/imagebutton-event-does-not-fire-if-imagebutton-does-not-have-image

Debug Timewaster #2

Make sure your file name doesn't include spaces or else Firefox will NOT know how to handle the file!
  • the file name will be truncated after the first word
  • the .csv extension will be missing
  • firefox may append .xls to your file name automatically
  • and when the file opens in Excel it will NOT be formatted into nice columns!
IE handles the spaces in the file name just fine.


Firefox CSV file extension issue

http://forums.mozillazine.org/viewtopic.php?f=38&t=661368&start=0&st=0&sk=t&sd=a
From: vipworld (guest)
Posted July 20th, 2008, 11:20 pm
"I was searching and looking for a solution as to why firefox would not assign a .csv extension to my csv files. It turned out that a space in the filename was causing the problem. Hope this can help some developer..."

Well brother, you did indeed help out a developer!  If you ever read this, thanks man! 

Such a stupid issue that wasted 30 minutes of reading through site after site regarding mime types and what not when the real problem was Firefox's inability to handle spaces in the file name.  Come on Mozilla, I know you can do better =P

Funny fact that made me laugh was that his entry was on July 20th haha.



Next 5 >>