Solved

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

Posted on 2006-11-16
3
180 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now