Solved

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

Posted on 2006-11-16
3
181 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

777 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