Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing LIKE operator without limiting results
    primarykey
    data
    text
    <p>I have the following query, the objective of which is to display a list of "items" which contain a series of "tags". Furthermore, I have chosen to display only "5" tags for each "item" as you can appreciate below:</p> <pre><code>$query = mysql_query("SELECT i.*, SUBSTRING_INDEX(GROUP_CONCAT(t.name), ',', 5) tagList FROM items AS i LEFT JOIN tag_rel AS tr ON (tr.item = i.id) LEFT JOIN tags AS t ON (t.id = tr.tag) GROUP BY i.id"); </code></pre> <p>Ok, that's great. It gives me something like this:</p> <p>[ITEM 1] tag1, tag2, tag3, tag6, tag8</p> <p>[ITEM 2] tag1, tag3, tag11, tag15, tag16</p> <p>[ITEM 3] tag2, tag4, tag5, tag6, tag7</p> <p>etc</p> <p>But here's the thing: if want to display a list of "items" which are "tagged" with "<strong>tag2</strong>" by adding:</p> <pre><code>WHERE (t.name LIKE 'tag2') </code></pre> <p>My result is simply:</p> <p>[ITEM 1] <strong>tag2</strong></p> <p>[ITEM 3] <strong>tag2</strong></p> <p>Showing me the items that, in fact, are tagged with "<strong>tag2</strong>" but limiting the "tags" to just that one. What I <em>really want</em> as a result are these two items (the ones tagged as "<strong>tag2</strong>") with all their tags:</p> <p>[ITEM 1] tag1, <strong>tag2</strong>, tag3, tag6, tag8</p> <p>[ITEM 3] <strong>tag2</strong>, tag4, tag5, tag6, tag7</p> <p>I have tried to use</p> <pre><code>WHERE (tagList LIKE '%tag2%') </code></pre> <p>But that just gives me:</p> <pre><code>Invalid query: Unknown column 'tagList' in 'where clause' </code></pre> <p>I hope I made myself clear. Many thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    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