Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    50
    Member #
    31189

    OR mysql search problem

    I've built what I think is a pretty cool and quirky db. 1 table with 4 columns. The columns are a, b, x, and y. A is basically a list of names. B gives info about those names. Very simple. db_table is searched through:
    PHP Code:
    $sqlsearch "SELECT a, b, x, y FROM db_table WHERE a LIKE '%$ask%'"
    It works fine. But because content in column a isn't widely known, I can't really expect people to know what they can search for. So I thought to make db_table searchable by column b, too. Column b basically gives info on the characteristics of a.

    PHP Code:
    $sqlsearch "SELECT a, b, x, y FROM db_table WHERE a OR b LIKE '%$ask%'"
    The problem is that this doesn't work for every a. There are terms that mysql_query gives 0 results.

    I also want to mention that the material in column b include parentheses, commas, dashes, \n, etc. To include an example of an entry:

    PHP Code:
    ('Adam''Adam has a mom.  Adam's mom once said"I took Adam and his friends for breakfast - sit was fun.\n We also went to the movies."\n', 'x', y, 0); 
    0 is for a page_views column that phpmyadmin sets up. I use utf8 for db_table.

    Is it possible the variety of characters in b is the reason why the db_table doesn't get searched properly when I use OR?

    varchar is used.
    Last edited by acegreen; Jun 03rd, 2014 at 11:35 AM.

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    I'm no SQL expert by any stretch, but aren't you supposed to escape the single and double quotes? That might be the problem.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Member #
    39504
    Liked
    1 times
    Try:
    SELECT * FROM tablename WHERE about REGEXP '(yoursearchterm|a|b)'
    Last edited by hutchzilla; Jul 10th, 2014 at 12:07 PM. Reason: Stupid Phone Autocorrect

  5. #4
    Member DerrickE's Avatar
    Join Date
    Jul 2007
    Location
    Houston, TX
    Posts
    58
    Member #
    15580
    Liked
    10 times
    You almost had it right, you just needed to have two like sections a like OR b like.
    This should work
    $sqlsearch = "SELECT a, b, x, y FROM db_table WHERE a LIKE '%$ask%' OR b LIKE '%$ask%'";


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Tags for this Thread

All times are GMT -6. The time now is 10:36 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com