How do I return the product from only using the first three letters? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How do I return the product from only using the first three letters?

MibbleMibble Posts: 1Member
Hello,

I have a MySQL database, which is accessed via php, one of the tables is named products, within the table is a field named products_model, which contains all the products used for the application. Some start with DVD, some with VHS, others with DJ, SE, etc. What i am wanting to do is to select and display only certain items, where I can use the first two or three characters to filter for displaying.

All products_model have up to 8 alpha-numeric characters.

I know this is basic, however I am just learning. The section marked in red is what I am trying to figure out how to code that.

Any help is appreciated.

here is the line I want to modify:

$products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name" . $new_fields . " from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1'" . SHOW_PRODUCTS_NEW_SINCE2 . [red]"and p.products_model = "[/red] . " and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'" . $order_by;

Comments

  • ManningManning Posts: 1,621Member
    : Hello,
    :
    : I have a MySQL database, which is accessed via php, one of the tables is named products, within the table is a field named products_model, which contains all the products used for the application. Some start with DVD, some with VHS, others with DJ, SE, etc. What i am wanting to do is to select and display only certain items, where I can use the first two or three characters to filter for displaying.
    :
    : All products_model have up to 8 alpha-numeric characters.
    :
    : I know this is basic, however I am just learning. The section marked in red is what I am trying to figure out how to code that.
    :
    : Any help is appreciated.

    If I understand correctly, you want to retrieve all the records that start with DVD, or all the records starting with VHS, or DJ, etc..?

    If so, you can use LIKE to match a partial value. So:

    SELECT * FROM Products WHERE Product_Model LIKE 'DVD%'

    That'll return all the products with a product model that starts with DVD.
Sign In or Register to comment.