Reputation: 33
I just have a little question about a query making me crazy. I'm working with CI, and tis is the first time i'm using this great framework
1— Okay so I have an insert query working rather well :
$data = array(
'nom' => $nom,
'prenom' => $prenom,
'login' => $prenom.' '.$nom,
'password' => 'facebook',
'email' => $fb_data['me']['email'],
'mobile' => "00",
'etat' => "1",
'role' => "1",
'ville' => 'ville actuelle',
'facebook_id' => $fb_data['uid'],
);
$this->db->insert('membre', $data);
And I don’t understand why it always insert the data twice ... !
2— Then I got a second question : I just wanna found a user with the related facebook_id so i try that :
$this->db->select('nom');
$this->db->from('membre');
$this->db->where('facebook_id',$fb_data['uid']);
$resultat=$this->db->get();
echo '<pre>';
print_r($resultat);
echo '</pre>';
I’ve also tried :
$resultat2 = $this->db->get_where('membre',array('facebook_id' => $fb_data['uid']));
echo '<pre>';
print_r($resultat2);
echo '</pre>';
But in both case, the only array I got is :
CI_DB_mysql_result Object
(
[conn_id] => Resource id #36
[result_id] => Resource id #61
[result_array] => Array
(
)
[result_object] => Array
(
)
[custom_result_object] => Array
(
)
[current_row] => 0
[num_rows] => 1
[row_data] =>
)
So the [result_id] is okay, but there is no data (as far as it is supposed to be printed in [row_data] ?) When I simply try on mysql i got the right result with the right member. But with CI, it doesn’t seems to work.
3— Furthermore, when i Try something like that :
echo $resultat['nom'];
it isn’t considered as an array ..
So .. yeah, I don’t really understand .. If anyone could enlight me ?
Upvotes: 1
Views: 2485
Reputation: 915
for 2 and 3
that will be work with you
$this->db->select('nom');
$this->db->from('membre');
$query = $this->db->get_where('facebook_id',$fb_data['uid']);
$row= $result->row();
echo '<pre>';
echo'$row->uid'; // that will prent user id , you can change to what ever you want ex. i want tp prent username it will be like this $row->username it should be same as database column
echo '</pre>';
Upvotes: 0
Reputation: 6027
1 - are you sure you don't call insert(...)
twice? Maybe you can use $this->db->last_query()
to see the result query.
Upvotes: 0
Reputation: 37701
Don't forget to use the result() method at the end, otherwise you only get resource. Like this:
$resultat2 = $this->db->get_where('membre',array('facebook_id' => $fb_data['uid']))->result();
This answers the second and third questions, as for the first I'd need to see how are you calling it - the code looks okay and my bet is you're probably somehow calling it twice.
Upvotes: 4