Results 1 to 4 of 4

Thread: [RESOLVED] Having trouble with a MySQL LIKE Statement

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Uk
    Posts
    157

    Resolved [RESOLVED] Having trouble with a MySQL LIKE Statement

    My database can have several products in one column 'Products' e.g. Product1,Product2,Product3

    I've created a webpage where the user can purchase a 2nd product at a discounted price - however the 2nd product must be the same Product as a previously ordered product

    I'm just stuck on the last part of the SQL query

    PHP Code:
    WHERE        (CustomerEmail = @CustomerEmail) AND (IsPaid = - 1)  AND (Product = @Product
    Product is the Database Column & @Product is the webpage form checkbox

    I want the query to search the database for the customers email where they have paid and the product they have selected matches one they have previously ordered

    I've tried

    PHP Code:
    WHERE        (CustomerEmail = @CustomerEmail) AND (IsPaid = - 1)  AND (Product LIKE @Product
    which half works - if there is only one product in the database - it fails if there is more than one product

    So i tried

    PHP Code:
    WHERE        (CustomerEmail = @CustomerEmail) AND (IsPaid = - 1)  AND (Product LIKE '%@Product%'
    However that give me an error when i compile the project saying there is too many arguements in the getdata queries which contain product

    da.GetDataByCustomerEmail(CustomerEmail, Product)

    Any idea where im going wrong?

  2. #2
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: Having trouble with a MySQL LIKE Statement

    Code:
    (Product LIKE '%@Product%')
    You are not using the values contained in @Product parameter if you put it inside quotes.

    I do not know MySQL but seems like you can try this:
    Code:
    select * from tblUser where Name LIKE CONCAT('%', ? ,'%');
    Source: http://dev.mysql.com/doc/refman/4.1/...functions.html

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Uk
    Posts
    157

    Re: Having trouble with a MySQL LIKE Statement

    Thanks for the link, i tried a couple of variations but get parse errors
    PHP Code:
    WHERE        (CustomerEmail = @CustomerEmail) AND (IsPaid = - 1LIKE Product ('%', @Product,'%'

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Having trouble with a MySQL LIKE Statement

    Hello experience,

    You seem to have marked the thread resolved, but your last comment makes me think that you are still having problems. Are you?

    If not, can you post your final solution?

    Gary

Posting Permissions

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



Click Here to Expand Forum to Full Width