Latest Post

Error: No input file specified.

While trying to run a codeigniter app the other day I came across this error just after I had finished uploading the files and making the ne...

Tuesday, August 3, 2010

PHP: Exporting a mySQL table to CSV

$rsSearchResults = mysql_query($sql, $connDb) or die(mysql_error());

$out = '';
$fields = mysql_list_fields('dbname','tablename',$connDb);
$columns = mysql_num_fields($fields);

// Put the name of all fields
for ($i = 0; $i < $columns; $i++) {
$l=mysql_field_name($fields, $i);
$out .= '"'.$l.'",';
$out .="\n";

// Add all values in the table
while ($l = mysql_fetch_array($rsSearchResults)) {
for ($i = 0; $i < $columns; $i++) {
$out .='"'.$l["$i"].'",';
$out .="\n";
// Output to browser with appropriate mime type, you choose ;)
$filedate = date('d-m-Y');
header("Content-type: text/x-csv");
//header("Content-type: text/csv");
//header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=filename-$filedate.csv");
echo $out;

If you wish to write the output to a file on the server instead then use file manipulation functions fopen() and fwrite()

Wednesday, July 7, 2010

Turn on php error reporting using code

//To turn on PHP error reporting using code use the lines below



How to force your form to open in the top frame

The typical way to do that is to add the script:

[javascript tag]

if (window != top) {
top.location.href = location.href;

[/javascript tag]

Put it as early in the head section as reasonable.

Monday, June 21, 2010

Tuesday, June 8, 2010

How to generate mysql update sql statement from an excel document

This assumes that you have a unique identifier in at least one of the columns.

1) In you source excel document insert a column and in that column we want to concatenate an update string similar to the example below:
="update mysql_table_name set fieldname = '"&A1&"',fieldname2='"&B1&"' where id = "&C1&";"

2) Copy this formula down to generate all the required update statements

3) Create another column, copy the recently generated column of fomulas, right click in the new column, choose "paste special" and select the "values" option

4) Copy the recently pasted values, i.e. the update sql statements into you mysql db query engine e.g. phpMyAdmin and run the queries. Your mysql table is now updated with the values from the excel sheet.

Not the most elegant way of doing things i know, but it worked for me on several occasions :)

Wednesday, May 12, 2010

document.form.submit is not a function

This is because you have a function trying to call the form's submit() method, and at the same time you have a form element, (in most cases a button), which is called submit(). This causes a conflict in javascript, because the submit method is already bound to that element (button).

To solve the problem, simply change the name of the element(button). The submit() call in your javascript function should now work.

Monday, February 22, 2010

Get number of days from a given mysql date field

Using mysql's inbuilt TO_DAYS() and CURDATE() functions one can determine the number of days from a given mysql date field to date.

SELECT date_field, CURDATE() AS Current_Date, (TO_DAYS( CURDATE() ) - TO_DAYS( date_field )) as difference FROM table_name


date_field Current_Date difference
---------- ------------ ------------
2010-02-11 2010-02-22 11
2010-02-10 2010-02-22 12

Friday, February 19, 2010

Dreamweaver startup javascript errors

"The following JavaScript error(s) occurred: At line 56 of file "C:\Program Files\Macromedia\Dreamweaver 8\Configuration\Shared\Common\Scripts\dwscriptsExtData.js": ReferenceError: dwscripts is not defined."

If you are experiencing a JavaScript errors related to "dwscripts" (see above) or if you are receiving a "translators were not loaded" error message when Dreamweaver 8 is starting up then you may try the following recommendations from the Adobe site:

Remove the WinFileCache-7A9586CB.dat file from the Dreamweaver user configuration folder. If that doesn't solve it, then recreate the Dreamweaver user configuration folder.

Delete FileCache.dat files from the Dreamweaver user configuration folder.

Delete the WinFileCache-7A9586CB.dat, MacFileCache-BFE7CE2E.dat, or FileCache.dat file from the Dreamweaver user configuration folder. It is recommended to delete the FileCache.dat file if you are experiencing a JavaScript error related to "dwscripts" or if you are receiving a "translators were not loaded" error message. The string of characters after "FileCache-" may differ on your machine. The location of the FileCache.dat file depends your operating system and your version of Dreamweaver. Note that on Windows, the Application Data and AppData folders are hidden by default, so verify that your Windows Explorer folder options are set to View Hidden Folders.
Dreamweaver CS3 on Windows Vista:
C:\Users\[username]\AppData\Roaming\Adobe\Dreamweaver 9\Configuration

Dreamweaver CS3 on Windows XP:
C:\Documents and Settings\[username]\Application Data\Adobe\Dreamweaver 9\Configuration

Dreamweaver 8 on Windows XP:
C:\Documents and Settings\[username]\Application Data\Macromedia\Dreamweaver 8\Configuration

Dreamweaver 8 on Windows Vista:
C:\Users\[username]\AppData\Roaming\Macromedia\Dreamweaver 8\Configuration

Dreamweaver CS3 on Macintosh:
Mac HD/Users/[user]/Library/Application Support/Adobe/Dreamweaver 9/

Dreamweaver 8 on Macintosh:
Mac HD/Users/[user]/Library/Application Support/Macromedia/Dreamweaver 8/


Tuesday, February 16, 2010

Javascript - how to continue text in next line

var sometText = 'abc\

This will not result in a javascript error because each time javascript encounters the single backslash, "\" it knows the statement continues on the next line.

Without the "\", Javascript will assume that the line has ended and give an "unterminated string constant" error.

Tuesday, January 26, 2010

"Cannot send session cache limiter - headers already sent"

For the files that were giving me this error, they were saved with the encoding set to UTF-8 and not ANSI. Once I saved the PHP files as ANSI they started working.

I found this fix from this forum

Hope this helps someone

Chitika Ads