Solved

Mysql / PHP Quesiton, Has to be easy.....

Posted on 2006-11-16
3
182 Views
Last Modified: 2010-04-16
Hey all,
I want to set up my mysql table so that if I have data like model numbers:

1, 12, 14, 16

I can do a query for select id from printers where model_numbers like '%1%'

Will select ONLY 1 not 12 14 and 16 also because they have a "1" in them.

Thanks for the help!!
0
Comment
Question by:wglenn01
  • 2
3 Comments
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17957422
If you want an exact match use

WHERE id = 1


LIKE clauses are used specifically for where you want to match 1, 12, and 14 all at once.
0
 

Author Comment

by:wglenn01
ID: 17957636
Doesn't quite work either.
See I have a table of printer cartridges. One of the fields is model_numbers these are the models this cartridge fits.

1, 12, 16

I have to have the query select from model_numbers where series=1 and series=12

if I do Where series = 1; it only pulls up in one category.

William
0
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 500 total points
ID: 17957826
I see, so you have a table printer_cartridges, and one row might contain "1, 12, 16" in a single field?

A much more desirable solution would be to create a separate table "linking" cartridges to models, so that you'd only have one value in each field; you'd just have multiple rows for each cartridge (and multiple rows for each model).

If there's absolutely no way to normalize the table structure, then..

SELECT stuff
FROM printer_cartridges
WHERE FIND_IN_SET('1', model_numbers) > 0;

(of course, replacing '1' with the model you're trying to match)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

856 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