Solved

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

Posted on 2006-11-16
3
183 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
This is an explanation of a simple data model to help parse a JSON feed
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

732 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