Note that there are some explanatory texts on larger screens.

plurals
  1. POprint() function! Error 4096 object could not be converted to string
    text
    copied!<p>I have a variable called <strong>$result</strong> which should store all the results from my database query however when I run print ($result) it gives an error message:</p> <blockquote> <p>A PHP Error was encountered</p> <p>Severity: 4096</p> <p>Message: Object of class CI_DB_mysql_result could not be converted to string</p> <p>Filename: models/control_panel_model.php</p> <p>Line Number: 72</p> </blockquote> <p>Here is my model code:</p> <pre><code>public function view_record($record_id) { $criteria = array ( 'procedure_id' =&gt; $record_id ); echo $this-&gt;db-&gt;count_all('procedure'); return; $this-&gt;db-&gt;select('procedure.procedure_id, procedure.patient_id, procedure.department_id, procedure.name_id , procedure.dosage_id'); $this-&gt;db-&gt;from ('procedure'); $this-&gt;db-&gt;join('patient', 'patient.patient_id = procedure.patient_id', 'inner'); $this-&gt;db-&gt;join('department', 'department.department_id = procedure.department_id', 'inner'); $this-&gt;db-&gt;join('procedure_name', 'procedure_name.procedure_name_id = procedure.name_id', 'inner'); $this-&gt;db-&gt;join('dosage', 'dosage.dosage_id = procedure.dosage_id', 'inner'); $this-&gt;db-&gt;where('procedure_id', $record_id); $result = $this-&gt;db-&gt;get(); print($result); return ; } </code></pre> <p>The reason I am using a print function is just to test if my query is working and it has values. How do I achieve this.</p> <p>Thanks</p> <p>EDIT!!!</p> <p>Here is what I get in var_dump();</p> <pre><code>object(CI_DB_mysql_result)#22 (8) { ["conn_id"]=&gt; resource(30) of type (mysql link persistent) ["result_id"]=&gt; resource(40) of type (mysql result) ["result_array"]=&gt; array(0) { } ["result_object"]=&gt; array(0) { } ["custom_result_object"]=&gt; array(0) { } ["current_row"]=&gt; int(0) ["num_rows"]=&gt; int(0) ["row_data"]=&gt; NULL } </code></pre> <p>I HAVE ADDED THE FOLLOWING CODE:</p> <blockquote> <p>if ($result->num_rows >0) { echo "Data"; } else { echo "No Data"; }</p> </blockquote> <p>IT IS SAYING THERE IS <strong>"NO DATA"</strong> so my query must be crap and wrong , so I need to redesign query. THERE IS DATA IN MY DATABASE SO must be query</p> <p>===========================================</p> <p>Here is my schema <a href="https://i.imgur.com/Dju0G.png" rel="nofollow noreferrer">http://i.imgur.com/Dju0G.png</a></p> <p><img src="https://i.stack.imgur.com/hdGmZ.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload