Showing posts with label programming blog. Show all posts
Showing posts with label programming blog. Show all posts

Friday, February 1, 2008

My Programmer's Notebook is back!

At last! It's been a while since blogger mistakenly took my blog as a spam blog. My last post was December 14 last year and after about 5-6 times trying to validate my blog, it's now back. My other blog also had the same problem. But it took around 6 days only when they get it back up again.

I will be posting lots of things soon...

By the way, today is my girlfriend's birthday! :)

Wednesday, November 28, 2007

Slow programming day...been traveling

I just arrived at my parents house today. I came here to visit them until the Christmas season. I've been traveling whole day so no programming for me today. Travel is 5 hours total which consists of 3.5 hours of land travel and 1.5 hours by plane :). I'm going rest for the rest of the day then I will continue programming tomorrow. I'll be back soon to post what I have done.

.... I miss my girlfriend already.. hehehe.

Sunday, November 25, 2007

Exporting mysql data to csv

Today I'm going to discuss the opposite of the previous post. Here it is :

/*some checking here like if the user is logged in, this is important in cases where we don't want other users to get hold of the data*/

//connect to the mysq;
define('host', 'localhost'); //Mysql Server name
define('database', 'dbname'); //Mysql Database name
define('user', 'dbuser'); //Mysql Username
define('password', 'dbpassword'); //Mysql Password
$dbtable = "dbtable";
$connection = mysql_connect(host,user,password);
$db = mysql_select_db(database,$connection);

$sql = mysql_query("select * from ".$dbtable.");

$fields = mysql_list_fields("yourdatabasename",$dbtable);
$columns = mysql_num_fields($fields);
$output = '';

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

$output .="\n";

//we now put all values from table
while ($l = mysql_fetch_array($sql))
{
for ($i = 0; $i < $columns; $i++)
{
$output .='"'.$l["$i"].'",';
}

$output .="\n";
}

// Output to browser with appropriate mime type, you choose
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=yourcsvfile.csv");
echo $output;
exit;

?>

This script will prompt for a download for the csvfile named yourcsvfile.csv which contain all the columns and entries from the table dbtable.

Monday, November 19, 2007

Blogging Sounds Fun

After hearing about blogs from friends and the internet, I decided to make my own blog. I thought it's better to let out my thoughts and share it with other people who might be interested. And I thought it would be better to have like an online diary for my life as a freelance web programmer and share what I have learn for all the times I've been working and of course share what I'm going to learn in the future.

This is good because not only I get to share my thoughts and experiences, I can also get people to share their opinions and can help me improve in some ways. I might also want to look back in the future for all the things I've done with my work and this would be very helpful because I can look back and relive those things again. Oh yeah.. this can help me improve my english too! :D

For the my next blog entries, I will post the daily things I have done and perhaps an overview of what I'm going to do on the next few days(or months). I'm hoping and very excited to write my next entry soon. Till then...