Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-16
3
Medium Priority
?
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Introduction to Processes

636 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