Note that there are some explanatory texts on larger screens.

plurals
  1. POQuery design issue
    primarykey
    data
    text
    <p>I have a nested list in this table <code>address</code>: </p> <pre><code>name |lft | rgt | ------------+----+-----+ Australia | 1 | 10 | nsw | 2 | 9 | sydney | 3 | 8 | kensington | 4 | 5 | kingsford | 6 | 7 | ------------+----+-----+ </code></pre> <p>Table explanation:As you can see the Australia includes all the others below it from the left and right value. the same applies to nsw and sydney, they contain what's below them. kensington and kingsford have the same depth and they belong to sydney. </p> <p>I am trying here to write a query for an auto complete search. I want when I type 'k' I get these results: </p> <pre><code>--&gt;kensington, sydney, nsw, australia --&gt;kingsford, sydney, nsw, australia </code></pre> <p>The current query:</p> <pre><code> 'SELECT parent.name FROM address AS node, address AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt AND node.name LIKE ' . $input </code></pre> <p>the query that I have does return the same values but "mixed up" as follows:</p> <pre><code> Array ( [0] =&gt; australia [name_en] =&gt; australia ) Array ( [0] =&gt; australia [name_en] =&gt; australia ) Array ( [0] =&gt; NSW [name_en] =&gt; NSW ) Array ( [0] =&gt; NSW [name_en] =&gt; NSW ) Array ( [0] =&gt; sydney [name_en] =&gt; sydney ) Array ( [0] =&gt; sydney [name_en] =&gt; sydney ) Array ( [0] =&gt; kensington [name_en] =&gt; kensington ) Array ( [0] =&gt; kingsford [name_en] =&gt; kingsford ) </code></pre> <p>The result that I seek is this</p> <pre><code> Array ( [0] =&gt; australia [name_en] =&gt; australia ) Array ( [0] =&gt; NSW [name_en] =&gt; NSW ) Array ( [0] =&gt; sydney [name_en] =&gt; sydney ) Array ( [0] =&gt; kensington [name_en] =&gt; kensington ) Array ( [0] =&gt; australia [name_en] =&gt; australia ) Array ( [0] =&gt; NSW [name_en] =&gt; NSW ) Array ( [0] =&gt; sydney [name_en] =&gt; sydney ) Array ( [0] =&gt; kingsford [name_en] =&gt; kingsford ) </code></pre> <p>It should return path after another.</p> <p><a href="http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/" rel="nofollow">http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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