0

I have a problem getting the number of rows from my tables.

Here is my mysql query using codeiginiter:

$this->db->where('rd', 1);
$this->db->where('id_user_first', $user_type);
$this->db->from("messaging");
$this->db->join('answers', "answers.id_message = messaging.id AND answers.id_user != '$user_type'");
$count_reponse  = $this->db->count_all_results();

I get this error message:

Parse error: syntax error, unexpected '' '' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in

Ank
  • 1,864
  • 4
  • 31
  • 51
S Triss
  • 3
  • 6

2 Answers2

2

You can try this solution for your problem :

Please changes query

$this->db->select('messaging.*, answers.*');
$this->db->from("messaging");
$this->db->join('answers', "answers.id_message = messaging.id");
$this->db->where('answers.id_user <>', $user_type);
$this->db->where('messaging.rd', 1);
$this->db->where('messaging.id_user_first', $user_type);
$count_reponse  = $this->db->count_all_results();
NikuNj Rathod
  • 1,663
  • 1
  • 17
  • 26
0

You need to escape your quotes or change the inner double-quotes to single quotes.

$this->db->join('answers', 'answers.id_message = messaging.id AND answers.id_user != '.$user_type.'','left');

Try This query:

$this->db->where('rd', 1);
$this->db->where('id_user_first', $user_type);
$this->db->from("messaging");       
$this->db->join('answers', 'answers.id_message = messaging.id', 'left');        
$this->db->where('answers.id_user !=', $user_type);
$count_reponse  = $this->db->count_all_results();

I hope it will help. Please leave a comment if any error came.

always-a-learner
  • 3,671
  • 10
  • 41
  • 81