Solved

Full Word Search Containing one word

Posted on 2013-06-17
4
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 110

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 110

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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

710 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