monkeybidz Posted April 6, 2010 Share Posted April 6, 2010 Here is the code I need help with. $result2 = mysql_query("SELECT * FROM sponsored_ads WHERE keywords2 LIKE '$keyword'"); for ($i = 0; $i <=3; $i++) { $in[] = $keys[$i]; } foreach ($results2 as $_key => $_row) { $last_domain2 = $domain_name2; extract($_row); } I just need it to return up to 3 results that match $keyword defined by user. Quote Link to comment https://forums.phpfreaks.com/topic/197798-need-help-with-a-query/ Share on other sites More sharing options...
Chris92 Posted April 6, 2010 Share Posted April 6, 2010 "SELECT * FROM sponsored_ads WHERE keywords2 LIKE '$keyword' LIMIT 3" Quote Link to comment https://forums.phpfreaks.com/topic/197798-need-help-with-a-query/#findComment-1037984 Share on other sites More sharing options...
monkeybidz Posted April 6, 2010 Author Share Posted April 6, 2010 Thanks for the reply. I did not explain that the code is not working at all. It was working before, but it was changed and some lines got lost or changed. Just need to get get the query to give me the results per row. Quote Link to comment https://forums.phpfreaks.com/topic/197798-need-help-with-a-query/#findComment-1038022 Share on other sites More sharing options...
jcbones Posted April 6, 2010 Share Posted April 6, 2010 <?php $result2 = mysql_query("SELECT * FROM sponsored_ads WHERE keywords2 LIKE '$keyword' LIMIT 3"); if(mysql_num_rows($result2) > 0) { while($r = mysql_fetch_assoc($result2)) { //call the rows. $domain = $r['domain']; } } else { echo 'There are no rows to print to the page!'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/197798-need-help-with-a-query/#findComment-1038027 Share on other sites More sharing options...
monkeybidz Posted April 6, 2010 Author Share Posted April 6, 2010 You got me on the right track. Here's what I did: $result2 = mysql_query("SELECT link2, title2, description2, keywords2 FROM sponsored_ads WHERE keywords2 LIKE '$keywords' LIMIT 3"); if(mysql_num_rows($result2) > 0) { while($r = mysql_fetch_assoc($result2)) { //call the rows. $link2 = $r['link2']; } echo "$link2"; } } Quote Link to comment https://forums.phpfreaks.com/topic/197798-need-help-with-a-query/#findComment-1038047 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.