Solved

Full Word Search Containing one word

Posted on 2013-06-17
4
249 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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
@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
Comment Utility
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

9 Experts available now in Live!

Get 1:1 Help Now