Mysql Copy Records With Insert Select Command

November 7, 2009 2 comments

mysql_logoThere’s a time you want to copy your MySQL row(s) into another table or on the same table. Here i’ll show you how to do it.

Let say, you have this table (lets name it tbl_persons), id is primary key and auto increment:

Id

Name Age Created
1 Billy 19 2009-11-06
2 Cindy 17 2009-11-06

Now you want to duplicate these two rows, but only the name, you can use insert select command query:

INSERT INTO `tbl_persons` (`Name`, `Age`, `Created`) SELECT `Name`, `Age`, CURDATE() FROM `tbl_persons` WHERE `Created` = '2009-11-06'

What this query to do is select the name that Created on 6th Nov 2009 and copy it into the same table but with different created date (for this example is the current date).

The result:

Id Name Age Created
1 Billy 19 2009-11-06
2 Chindy 17 2009-11-06
3 Billy 19 2009-11-07
4 Chindy 17 2009-11-07

Here’s another example if you want to copy field value into another table. This is the destination table (lets name it…umm… tbl_qualify), just the same with tbl_persons, id field is primary key and auto increment:

id Name
1 Glenn

This is the query:

INSERT INTO `tbl_qualify` (`Name`) SELECT `Name` FROM `tbl_persons` WHERE `age` > 18

The query is used to copy to tbl_qualify, but only the records (persons) that have age above 18.

Here is the final result:

id Name
1 Glenn
2 Billy

Well. That’s it 🙂 Feel free to give me some suggestions and critics.

If you interested see my other post and give me another feedback. Thanks!

Advertisements
Categories: MySQL Tags: , , , , ,

Playing Mafia Wars in Mobile Phone Browser

October 31, 2009 6 comments

mafia wars imageWell, if you haven’t see my previous post about WordPress webmaster tools, you can see it in here, or if you want to see PHP related post, you may want to see this and this.
Ok, here’s my next post. If you’re a Mafia Wars player on Facebook, and want to play it while you’re on a car or a train you can follow this suggestions:
1. Download Bolt Browser for your mobile phones. You can download it here. Or you can get it from getjar.com. Just search bolt browser from search box and download it to your phone. It is in jar format. Well, back to the topic, why Bolt, why not Opera Mini? It’s a very popular mobile browser! Well, because Zynga seems made some modification on the game, the latest Opera 4.2 can’t run the game very well. But Bolt can 😀
2. Run Bolt, and access the URL, and enjoy 😀

A little note about this suggestion, Mafia Wars is build for web browser, not a mobile browser. So don’t expect you have the same experience playing it on your phone.

If you have time to try it, give me some feedback about your experience 😀
And don’t forget to add me on Facebook (f4810_17@yahoo.com). Lets play! 🙂

New WordPress Webmaster Verification Tools

October 24, 2009 5 comments

Well, for you out there that use WordPress.com blog that haven’t verify your website using Google Webmaster Tools may be frustated about recent changes made by Google.

The old way seems cannot handle it anymore (for all of you who wrote how to verify your wordpress blog out there should update your post :D). Luckily WordPress is aware of it. They work hard for a solutions and they give a solution. Even better they give us tools about it!

So i’ll post the quick how-to do it, here you go:

  1. Get a Gmail account if you haven’t
  2. Access the Google Webmaster Tools
  3. In Home Page Click Add A Site, insert your WordPress url
  4. This will bring you to Verification Page

    Google Verify Site Page Image

    Google Verify Site Page Image

  5. Now Copy the meta tag as described there.
  6. Now open your blog dashboard that you want to verify.
  7. Choose tools from side menu, or turbo at the left side of log out  link.
  8. Find the WordPress Webmaster Verification Tools, you have to scroll down because it is in the bottom.
  9. Paste the meta tags you copied earlier into first input box and save changes

    Wordpress Webmaster Tools Image

    Wordpress Webmaster Tools Image

  10. Back to Verification Page and Verify, and it’s a wrap. Thanks WordPress 🙂

You can find the manual here

10 Tips for PHP Beginner

October 22, 2009 3 comments
PHP image

PHP image

One day my friend asked me one short question that will have very long (and not to mention it is vary between people) question: “What should I do as a newbie PHP programmer?”
Well, here are the answers from my personal experience, 10 answers exactly:
1. Be determined, be passionate
You won’t succeed if you don’t have this kind of attitude when it comes to learning programming (well…. not just programming though). It will give you a major advantage as you walk through this wild wild.. erm.. amazing world.
2. Reinventing The Wheel
Hey, what’s this? There’s many people say don’t do what others already done! Well… it’s better to know the detail of a car than just using it. As someone who knows the detail of the car can fix their own car, thus they can call themselves a mechanics… see the similarity with a programmer? To be a good programmer you should spend your time to build your own simple script, build your own function, or build your own framework.
3. Don’t Reinventing The Wheel
Don’t be confused about this… 😀 I said earlier you should spend your time to make your own php script. But not in every case! Sometimes it’s good to look to others script to make yourself improved. Balance is the key (yin yang anyone?)
4. Read some (good) book
Well… I don’t know if in other country have the same problems, but here in my country there’s many repetitive and boring programming books about PHP. Choose the right books and choose carefully please! Personally I like Gutman’s book and the one from O’Reilly, but you can choose any books easy for you to understand.
5. Don’t get too far away with the manual
Many many times when I begin to coding in PHP, the manual are always there to help me. So don’t forget to put it one your arsenal every time you starting a session of learning and working with PHP. RTFM 😀
6. Gain some from internet
There’s thousand.. no, even more resource on the internet to help you to progress. Examples are phpdeveloper.org and devnetwork.net
7. Learn from your surrounding
Don’t be afraid to ask. You will lose in the middle of nowhere if you won’t ask someone to help you. Ask everyone, especially the senior when you stuck in a problem. They often have the solution for you.
8. Look at your code six months from now and criticized yourself
If you look at it and think it’s ok then you’re doing something wrong. Be criticized about yourself. That way you can find some room for an improvement.
I read it from Brandon Savage Blog Here
9. Keep the life cycle
Don’t stop learning. Hey, the world constantly changes… so we have to do it in order to survive, right? It’s the same thing in programming. Always up to date about your knowledge. Don’t stop to learn.
10. Take some projects
This is the last answer, take some real deal project!! Feel the adrenaline!! There’s no better way to improve than this way. Implement every efforts and knowledge you have from learning phase. Besides, you cannot call yourself a programmer when you don’t do programming on some project don’t you?

Well that’s my answers. How about yours?

Categories: PHP Tags: , ,

Multi Level Subfolder Controller in CodeIgniter

October 20, 2009 57 comments
CI logo

CI logo

Well, this is my first post so be gentle to me :).

Recently i’m working on a web based application project using CodeIgniter framework. Problem arises when my boss wants this web application to have more than two level subfolder in controller folder (for example: /controller/company_a/admin/, /controller/company_a/reports/) for organizational purpose.

Read more…

First Run

October 16, 2009 Leave a comment

I haven’t write at all right now… But I’ll share my thoughts and personal experience (largely it will be about web application development) whenever i have any spare time. Thanks!

Categories: General Topics