Jump to content

Mysql search not working


ryanfilard

Recommended Posts

The results still return empty even when I type in the exact field name.

 

$idea = $_REQUEST['s'];
mysql_select_db($database_Users, $Users);
$query_search = "SELECT * FROM users WHERE username AND fname AND lname AND tags LIKE '$idea'";
$search = mysql_query($query_search, $Users) or die(mysql_error());
$row_search = mysql_fetch_assoc($search);

Link to comment
Share on other sites

username AND fname AND lname AND tags

 

^^^ The above is logically AND'ing the contents of each of those columns together, which most likely is a TRUE value (unless you have FALSE and/or NULL values), then trying to see if TRUE LIKE '$idea'

 

What exactly are you trying to accomplish?

Link to comment
Share on other sites

So, you want to match rows where any portion of the username is like $idea or any portion of the fname is like $idea or any portion of the lname is like $idea or any portion of the tags is like $idea?

 

SELECT * FROM users WHERE username LIKE '%$idea%' OR fname LIKE '%$idea%' OR lname LIKE '%$idea%' OR tags LIKE '%$idea%'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.