2

I am using CodeIgniter and MYSQL.

I have table1, which has one field (name).

In filed name it has values such as ABC,DDDD and EEE.

SQL statment:

value of field name
ABC
DDDD
EEE

Select name from table1

I want to convert data that i selected to formatted as the following.

Array ( [0] => ABC [1] => DDDD [2] => EEE ) 

Regards,

1 Answer 1

2

Use this code:

$q = $this->db->get('table1');
if ($q->num_rows() > 0):
   foreach($q->result() as $r):
       $data[] = $r->name;
   endforeach;
endif;

$data holds your array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.