PHP Related items from database <p>I have been googling for a while and searching SO but I still can't find an answer.</p> <p>So my problem is that I want to pull related content from mySQL database on what id is currently being displayed on the page. In the database I have a column dedicated to keywords, and I am using the LIKE query to pull id's based on those keywords. However, I get only one id because the LIKE query looks at the keyword literally. For example, keyword1 = 'apples berries oranges' is not the same as keywords2 = 'apples' 'berries' 'oranges'. I want the latter so it can pull in more related data.</p> <p>I also think I may be approaching this wrong, but I don't know any other way to pull related items.</p> <p>Here's my code...</p> <pre><code>&lt;?php include 'data/data_connect.php'; if ($sugg_qs = $db-&gt;query("SELECT * FROM questions WHERE keywords LIKE '$keywords' LIMIT 4")) { if ($q_count = $sugg_qs-&gt;num_rows) { echo $q_count; while($row = $sugg_qs-&gt;fetch_assoc()) { echo $row-&gt;title; } $sugg_qs-&gt;free(); } else { die('error'); } } else { die('error'); } ?&gt; </code></pre> <hr> <p>UPDATE</p> <pre><code>if ($sugg_qs = $db-&gt;query("SELECT * FROM questions WHERE keywords LIKE CONCAT('%', '$keywords' ,'%') LIMIT 3")) { if ($q_count = $sugg_qs-&gt;num_rows) { $row = $sugg_qs-&gt;fetch_all(MYSQLI_ASSOC); foreach ($row as $rows) { echo $rows['title']; } } else { die('error'); } </code></pre> <p>This code does work with id's that only have one keyword. So I guess a possible (but undesired) solution would be to create a new column for each new keyword and use LIKE for each keyword.</p> <p>Is there a way to avoid creating more columns?</p> <p>THANKS for those who helped already :)</p> <hr> <p>FINAL UPDATE? Ok. So I figured it out in probably the messiest way to write code, but apparently it works for me. So first of all I standardized my table where each element is limited to only 5 keywords and 1 category. So in the query I call for items with similar keywords, and if there aren't similar results I then call for items from the same category from the original item. </p> <p>Here is the (messy) code for those looking for a solution!</p> <pre><code>$q_kw_arr = explode(' ', $keywords); if ($sugg_qs = $db-&gt;query("SELECT keywords, category, title FROM questions WHERE keywords LIKE CONCAT('%', '$q_kw_arr[0]' ,'%') OR CONCAT('%', '$q_kw_arr[1]' ,'%') OR CONCAT('%', '$q_kw_arr[2]' ,'%') OR CONCAT('%', '$q_kw_arr[3]' ,'%') OR CONCAT('%', '$q_kw_arr[4]' ,'%') OR category= '$category' LIMIT 4")) { if ($q_count = $sugg_qs-&gt;num_rows) { $row = $sugg_qs-&gt;fetch_all(MYSQLI_ASSOC); foreach ($row as $rows) { echo $rows['title']; } } else { echo 'error'; } } </code></pre> <p>SPECIAL THANKS TO..</p> <p>Terminus, Grzegorz J, and infidelsawyer</p>