Solved

Full Word Search Containing one word

Posted on 2013-06-17
4
271 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 109

Accepted Solution

by:
Ray Paseur earned 500 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 109

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now