Mysql Copy Records With Insert Select Command
There’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!
10 Tips for PHP Beginner
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?
Multi Level Subfolder Controller in CodeIgniter

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.
First Run
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!
Well, if you haven’t see my previous post about WordPress webmaster tools, you can see it in 

