Note that there are some explanatory texts on larger screens.

plurals
  1. POUndefined variable: query - codeigniter
    text
    copied!<p>I am getting the message: </p> <p>A PHP Error was encountered</p> <p>Severity: Notice</p> <p>Message: Undefined variable: query</p> <p>Filename: views/main.php</p> <p>Line Number: 12</p> <p>This is the code for my controller:</p> <pre><code>function get_all(){ $this-&gt;load-&gt;model('book_model'); $this-&gt;load-&gt;library('table'); $this-&gt;load-&gt;helper('html'); $data['query'] = $this-&gt;books_model-&gt;books_getall(); $this-&gt;load-&gt;view('main', $data); } </code></pre> <p>And this is my view:</p> <pre><code>&lt;h1&gt; List of books in library&lt;/h1&gt; &lt;table border="1"/&gt; &lt;tr&gt; &lt;th&gt;ID&lt;/th&gt; &lt;th&gt;Title&lt;/th&gt; &lt;th&gt;Author&lt;/th&gt; &lt;th&gt;Information&lt;/th&gt; &lt;th&gt;Publisher&lt;/th&gt; &lt;th colspan="2"&gt;Action&lt;/th&gt; &lt;/tr&gt; &lt;?php if(is_array($query)){ foreach ($query as $row){ echo "&lt;tr&gt;"; echo "&lt;td&gt;".$row-&gt;id."&lt;/td&gt;"; echo "&lt;td&gt;".$row-&gt;title."&lt;/td&gt;"; echo "&lt;td&gt;".$row-&gt;author."&lt;/td&gt;"; echo "&lt;td&gt;".$row-&gt;information."&lt;/td&gt;"; echo "&lt;td&gt;".$row-&gt;publisher."&lt;/td&gt;"; echo "&lt;td&gt;".anchor('book/input'.$row-&gt;id,'Edit')."&lt;/td&gt;"; echo "&lt;td&gt;".anchor('book/delete'.$row-&gt;id,'Delete')."&lt;/td&gt;"; echo "&lt;/tr&gt;"; } } ?&gt; &lt;/table&gt; </code></pre> <p>Thanks in advance for any help</p> <p>Edit: This is my model code:</p> <pre><code>function get_all(){ $this-&gt;load-&gt;database(); $query = $this-&gt;db-&gt;get('books'); return $query-&gt;result(); </code></pre> <p>}</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