PHP, SQL Code not working <p>im ranning into some problems agian, and hope that your guys can help me.</p> <p>I have this code, that i can't get to work.</p> <p>see, the strange thing is, if i change</p> <pre><code>$query2 = mysqli_query($dblogin, "SELECT * FROM devices RIGHT JOIN repair ON devices.name = repair.modelid WHERE repair.modelid=$check"); </code></pre> <p>to</p> <pre><code>$query2 = mysqli_query($dblogin, "SELECT * FROM devices RIGHT JOIN repair ON devices.name = repair.modelid WHERE repair.modelid LIKE %iPad%"); </code></pre> <p>i will work, just fine :-/</p> <p>im really lost, and i tryed, to echo the $check, to see if there was an error in the $check variable. but thats works just fine.</p> <pre><code>&lt;div id="slidingDiv&lt;?=$row["id"] ?&gt;" class="toggleDiv row-fluid single-project"&gt; &lt;div class="span6"&gt; &lt;img src="adm/images/&lt;?=$row["image"] ?&gt;" alt="project &lt;?=$row["id"] ?&gt;" /&gt; &lt;/div&gt; &lt;div class="span6"&gt; &lt;div class="project-description"&gt; &lt;div class="project-title clearfix"&gt; &lt;h3&gt;&lt;?=$row["name"] ?&gt;&lt;/h3&gt; &lt;span class="show_hide close"&gt; &lt;i class="icon-cancel"&gt;&lt;/i&gt; &lt;/span&gt; &lt;/div&gt; &lt;div class="project-info"&gt; &lt;?php $check = $row["name"]; $query2 = mysqli_query($dblogin, "SELECT * FROM devices RIGHT JOIN repair ON devices.name = repair.modelid WHERE repair.modelid=$check"); while($row = mysqli_fetch_assoc($query2)) { ?&gt; &lt;div&gt; &lt;span&gt;&lt;?=$row["price"] ?&gt; ,-&lt;/span&gt;&lt;?=$row["name"] ?&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;div&gt; &lt;span&gt;Client&lt;/span&gt;Some Client Name &lt;/div&gt; &lt;div&gt; &lt;span&gt;Date&lt;/span&gt;July 2013 &lt;/div&gt; &lt;div&gt; &lt;span&gt;Skills&lt;/span&gt;HTML5, CSS3, JavaScript &lt;/div&gt; &lt;div&gt; &lt;span&gt;Link&lt;/span&gt;http://examplecomp.com &lt;/div&gt; &lt;/div&gt; &lt;p&gt;Believe in yourself! Have faith in your abilities! Without a humble but reasonable confidence in your own powers you cannot be successful or happy.&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>If i changes it, to this, it runs just fine</p> <pre><code>&lt;? $query = mysqli_query($dblogin, "select * from brands ORDER BY id"); while($row = mysqli_fetch_assoc($query)) { ?&gt; &lt;li class="filter" data-filter="&lt;?=$row["name"] ?&gt;"&gt; &lt;a href="#noAction"&gt;&lt;img class="aimg" style="height:50px;" src="adm/images/&lt;?=$row["image"] ?&gt;" /&gt;&lt;/a&gt; &lt;/li&gt; &lt;? } ?&gt; &lt;/ul&gt; &lt;!-- Start details for portfolio project 1 --&gt; &lt;div id="single-project"&gt; &lt;? $query = mysqli_query($dblogin, "select * from devices ORDER BY name DESC"); while($row = mysqli_fetch_assoc($query)) { ?&gt; &lt;div id="slidingDiv&lt;?=$row["id"] ?&gt;" class="toggleDiv row-fluid single-project"&gt; &lt;div class="span6"&gt; &lt;img src="adm/images/&lt;?=$row["image"] ?&gt;" alt="project &lt;?=$row["id"] ?&gt;" /&gt; &lt;/div&gt; &lt;div class="span6"&gt; &lt;div class="project-description"&gt; &lt;div class="project-title clearfix"&gt; &lt;h3&gt;&lt;?=$row["name"] ?&gt;&lt;/h3&gt; &lt;span class="show_hide close"&gt; &lt;i class="icon-cancel"&gt;&lt;/i&gt; &lt;/span&gt; &lt;/div&gt; &lt;div class="project-info"&gt; &lt;?php $check = $row["name"]; $query2 = mysqli_query($dblogin, "select * from devices right join repair on devices.name = repair.modelid WHERE repair.modelid LIKE '%iPhone 6%'"); while($row = mysqli_fetch_assoc($query2)) { ?&gt; &lt;div&gt; &lt;span&gt;&lt;?=$row["price"] ?&gt; ,-&lt;/span&gt;&lt;?=$row["name"] ?&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;? } ?&gt; </code></pre> <p><strong>EDIT</strong></p> <pre><code>SELECT * FROM devices RIGHT JOIN repair ON devices.name = repair.modelid WHERE repair.modelid LIKE '%iPhone 6%' LIMIT 0 , 30 </code></pre> <p>Gives this result </p> <pre><code>id name brand image model-id id name modelid price brand date 7 iPhone 6 Apple iphone6_small.jpg 217 Front Glas Udskiftning iPhone 6 1300 1432215986 7 iPhone 6 Apple iphone6_small.jpg 218 Bagside (komplet) iPhone 6 2500 1432216016 7 iPhone 6 Apple iphone6_small.jpg 219 TÃ¦nd/sluk Udskiftning iPhone 6 500 1432216041 7 iPhone 6 Apple iphone6_small.jpg 220 Homeknap iPhone 6 500 1432216064 7 iPhone 6 Apple iphone6_small.jpg 221 Ã˜rehÃ¸jtaler iPhone 6 500 1432216085 7 iPhone 6 Apple iphone6_small.jpg 222 Ladestik iPhone 6 500 1432216107 7 iPhone 6 Apple iphone6_small.jpg 223 Batteri iPhone 6 500 1432216124 7 iPhone 6 Apple iphone6_small.jpg 224 Vibrator iPhone 6 500 1432216136 7 iPhone 6 Apple iphone6_small.jpg 225 Mikrofon iPhone 6 500 1432216165 7 iPhone 6 Apple iphone6_small.jpg 226 Kamera iPhone 6 500 1432216177 7 iPhone 6 Apple iphone6_small.jpg 227 HÃ¸jtaler (musik/lyd) iPhone 6 500 1432216191 7 iPhone 6 Apple iphone6_small.jpg 228 WIFI Antenne iPhone 6 500 1432218537 7 iPhone 6 Apple iphone6_small.jpg 229 Jackstik iPhone 6 500 1432218564 7 iPhone 6 Apple iphone6_small.jpg 230 Jailbreak iPhone 6 500 1432218593 7 iPhone 6 Apple iphone6_small.jpg 231 Bagside (komplet) iPhone 6 2500 1432218612 </code></pre>