Welcome Guest, Not a member yet? Register   Sign In
Fetch value in query and store in array
#1

[eluser]rochellecanale[/eluser]
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:
Code:
mysql> SELECT DISTINCT(fkmember) FROM points_ledger;
+----------+
| fkmember |
+----------+
|        2 |
|       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.
#2

[eluser]skunkbad[/eluser]
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:

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

}
#3

[eluser]rochellecanale[/eluser]
I've tried your code. But how can I view all the result in array? I tried echo $arr[0]; but nothing displays.
#4

[eluser]skunkbad[/eluser]
[quote author="rochellecanale" date="1353477240"]I've tried your code. But how can I view all the result in array? I tried echo $arr[0]; but nothing displays.[/quote]

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

Code:
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.
#5

[eluser]rochellecanale[/eluser]
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?
#6

[eluser]rochellecanale[/eluser]
Ok i solved my answer what i did is like this:
Code:
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
#7

[eluser]ahmed.alsiddig[/eluser]
nice work




Theme © iAndrew 2016 - Forum software by © MyBB