Solved

Full Word Search Containing one word

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to remove %20 from url in get 17 36
reverse engineer .sql from php files 11 35
MYSQL responding very slow 3 26
How do I show metrics with PHP or Javascript 6 34
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

821 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