How To Show Data From Database Using PHP CodeIgniter + AngularJS

Hi.. this time I created simple web to show some data from database using PHP CodeIgniter and angularJS. Here is the screenshot of the result page:


I use MySQL as my db. Here is the table that I’ll use for sample:


First of all, I added some angular javascript files to my js folder. Since I use bootstrap for my csss,I added some bootstrap css too to my css folder. Now we ready for codes 🙂

For books_model, I created function to get all books in getAllBooks() function. Continue reading “How To Show Data From Database Using PHP CodeIgniter + AngularJS”

Insert Into Table Using Select Statement

Someday, I need to insert some records into table from a query or select statement. The basic syntax:

INSERT INTO  (xxxfield, yyyfield, zzzfield)
SELECT xxx, yyy, zzz from abc 

For example, if I want to inserting rows into table member from viewuser table

INSERT INTO member(name,username,lastlogin)
SELECT uname,uusername,ulastlogin
from viewuser
where state='CA';

if you want to add constant value, just add it on the query

INSERT INTO member(name,username,password,lastlogin)
SELECT uname,uusername,'bOH4y',ulastlogin
from viewuser
where state='CA';

Hope this simple article can help 🙂

How to Save Select Result Into CSV File on MySQL

Well .. if you ask me why we need make the select result into csv file, you will find it out when you work together with some people which is don’t know how to populate data like they wish. Sometimes it will get more easy to check the data using makro script or something else.

Here is the sample how to create the csv file.

In this sample case, I have table:

 PersonID int,
 LastName varchar(255),
 FirstName varchar(255),
 Address varchar(255),
 City varchar(255)

so, the script can be:

select * from Persons
into outfile '/Users/ariestania/Persons.csv'
fields terminated by ',' optionally enclosed by '"'
lines terminated by '\r\n';

if you don’t want get NULL value become “N\A” on CSV file, change to be like this:

select ID, LastName, FirstName,
CASE when Address is NULL then '' else Address end as Address,
CASE when City is NULL then '' else City end as City
from Persons
into outfile '/Users/ariestania/Persons.csv'
fields terminated by ',' optionally enclosed by '"'
lines terminated by '\r\n';


  1. You can change the select statement depend on your requirement.
  2. “/Users/ariestania/” is the folder where you want to put your csv file.
  3. “Persons.csv” is the name for your csv file.

Hope this article can help .. 🙂