Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter keeps returning an empty array in DB query
    text
    copied!<p>I have a two dimensional array which contains information about parent-cateogries (<code>parent=1</code>). Here is a <code>print_r()</code> of this array:</p> <pre><code> Array ( [0] =&gt; Array ( [id] =&gt; 2 [title] =&gt; parent2 [content] =&gt; this is an example [avator] =&gt; [thumnail] =&gt; [parent] =&gt; 1 [parent_id] =&gt; 8 ) [1] =&gt; Array ( [id] =&gt; 3 [title] =&gt; THISPARENT [content] =&gt; A NOTE [avator] =&gt; [thumnail] =&gt; [parent] =&gt; 1 [parent_id] =&gt; 12 ) ) </code></pre> <p>In this array I have two parents. Only one of them has already a child in database table, so when I search the Database for a child wholse parent_id should be one of the two, a logical result should be an array with the information of one child category, while it returns two arrays, one of which is empty.</p> <p>I search the DB using the above parent-cateogries' ids by using the below <code>loop</code>:</p> <pre><code> for($i=0; $i&lt;count($cats); $i++) { $this-&gt;db-&gt;where("parent_id", $cats[$i]['id']); $res = $this-&gt;db-&gt;get("category"); $x[$i] = $res-&gt;result_array(); } </code></pre> <p>Now, what I do receive as result is here: </p> <pre><code> Array ( [0] =&gt; Array ( ) [1] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 1 [title] =&gt; child [content] =&gt; childparent it is [avator] =&gt; [thumnail] =&gt; [parent] =&gt; 0 [parent_id] =&gt; 3 ) ) ) </code></pre> <p>While there should not be an empty zero-indexed array, I only expect to receive on array which I have already as the second index, the first empty! Why?</p> <p>thanks in advance</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