Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Full Word Search Containing one word

Posted on 2013-06-17
4
Medium Priority
?
300 Views
Last Modified: 2013-06-25
I want to only get results that contain only @bob but my current query gets  results with bob and bobby and other variations of bob.



$username = "bob";

$query = mysql_query("SELECT head.comment_id, friend_id, users.member_id, username, approved, UNIX_TIMESTAMP(date_posted) AS date_posted, comment_text, username FROM comments_head head FORCE INDEX(member_id), comments_body body, users WHERE head.comment_id = body.comment_id AND head.friend_id = users.member_id and body.comment_text LIKE '@$username%' order by head.comment_id desc limit " .$this->perpage) or die(mysql_error());

Open in new window

0
Comment
Question by:U_S_A
  • 2
  • 2
4 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39254823
Change this...

'@$username%'

... to this and let us know how it works out.

'@$username'

I'm not sure - you might need to prepend the @ to the $username variable before constructing the query.   But this is where I would start to test.
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 39268456
change '@$username%'  to '@$username'

$query = mysql_query("SELECT head.comment_id, friend_id, users.member_id, username, approved, UNIX_TIMESTAMP(date_posted) AS date_posted, comment_text, username FROM comments_head head FORCE INDEX(member_id), comments_body body, users WHERE head.comment_id = body.comment_id AND head.friend_id = users.member_id and body.comment_text LIKE '@$username' order by head.comment_id desc limit " .$this->perpage) or die(mysql_error());
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39268478
@insoftservice: Right.. Just like I said 5 days ago! ;-)

@U_S_A: You might try using var_dump() to print out the fully resolved query string.  Also, see the note about the MySQL Wild Card here:
http://www.tizag.com/mysqlTutorial/mysqlwhere.php
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 39268933
ya @Ray_Paseur.
just said by mysql long back when it had been developed if i am not wrong :).

Its one of common mysql wild card which normally all developers use right ?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we’ll look at how to deploy ProxySQL.
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question