EllisLab text mark
Advanced Search
     
Fetch value in query and store in array
Posted: 21 November 2012 01:29 AM   [ Ignore ]
Avatar
Joined: 2012-08-24
214 posts

Hello guys just need a little help in query. This is not a CI problem but I hope that you can help me.

This is my simple query result:

mysqlSELECT DISTINCT(fkmemberFROM points_ledger;
+----------+
fkmember |
+----------+
|        
|
|       
37 |
|       
38 |
|       
47 |
|       
53 |
|       
63 |
|       
64 |
|       
76 |
+----------+
8 rows in set (0.05 sec)

My problem is how can i get the fkmember value and store it in array.

I have a query like this:

$query1 "SELECT DISTINCT(fkmember) FROM points_ledger";
$result1 $this->db->query($query1);
            
foreach(
$result1->result_array() as $row){
         
        
//Need to get the value of fkmember and sore in array       

Because i want to create a two queries using the fkmember. That’s all hope you can help me.

 Signature 

Our greatest glory is not in never falling, but in rising every time we fall.

cheese
Email: .(JavaScript must be enabled to view this email address)
Mobile Number: +639216015372

 
Posted: 21 November 2012 01:39 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-05-17
1415 posts

If instead of using $result1->result_array() you use $result1->row_array(), then that is an array of all of the fkmembers. Is that what you’re asking for?

The way you have it now, you could do something like this:

foreach($result1->result_array() as $row){
         
        
//Need to get the value of fkmember and sore in array
        
$arr[] $row['fkmember'];

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application

 
Posted: 21 November 2012 01:54 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2012-08-24
214 posts

I’ve tried your code. But how can I view all the result in array? I tried echo $arr[0]; but nothing displays.

 Signature 

Our greatest glory is not in never falling, but in rising every time we fall.

cheese
Email: .(JavaScript must be enabled to view this email address)
Mobile Number: +639216015372

 
Posted: 21 November 2012 02:00 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-05-17
1415 posts
rochellecanale - 21 November 2012 01:54 AM

I’ve tried your code. But how can I view all the result in array? I tried echo $arr[0]; but nothing displays.

I’m sorry, but the answer to your question is basic knowledge of PHP.

print_r$arr ); 

You may find using CodeIgniter very difficult or impossible without first learning more PHP. I say that in all humbleness. PHP frameworks are meant to provide PHP developers with shortcuts, structure, and organization. It’s not practical to expect to be able to do much of anything in CodeIgniter without basic knowledge of PHP.

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application

 
Posted: 21 November 2012 02:04 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2012-08-24
214 posts

I know that my problem is I want to assign it in another variable. I want to extract it using a loop. How can i do that? print_r() is for displaying array structures am I right?

 Signature 

Our greatest glory is not in never falling, but in rising every time we fall.

cheese
Email: .(JavaScript must be enabled to view this email address)
Mobile Number: +639216015372

 
Posted: 21 November 2012 02:10 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2012-08-24
214 posts

Ok i solved my answer what i did is like this:

foreach($result1->result_array() as $row){
                
                $arr[] 
$row['fkmember'];
                
            
}
            
for($x=0$x<$numrows$x++){
                    
echo $arr[$x]."<br />";
            

Then it displays all the value in array. Thanks a lot for the help my friend. smile

 Signature 

Our greatest glory is not in never falling, but in rising every time we fall.

cheese
Email: .(JavaScript must be enabled to view this email address)
Mobile Number: +639216015372

 
Posted: 24 November 2012 05:27 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2012-09-20
15 posts

nice work