PDA

View Full Version : Query 3 chars ID with only 1 known char ?????????


bahytq
05-04-2003, 08:13 AM
I am doing a small project in mySQL and PHP , i don't know how to query something like this :
I have a table call member always contains 3 chars which has this format : the first char for the class ( eg. A,B,C,D...) and the 2 left chars stand for the order of that student in the class ( eg. in Alphabet order ....) . I want to have the list of all student in the class A ,no matter what the order of that student is . then how do i code ? i did something like this
SELECT * FROM member WHERE memberid ="A??" because i think it will return only the records in the table member which contains the memberid that has only the first char is "A" .

but it returns no records although it told me that "Your SQL-query has been executed successfully " .

It was really so hard to solve it myself , anyone has won this please help me .

raf
05-04-2003, 11:02 AM
For starters, if you have a columnname/variablename with ID in it, most coders will presume it is a numerical value, so folowing some basic codingconventions would help you and others to stay out of problems). Then most coders (i think it's necessary) use single quotes for values of textvariables.

As far as i know, MySQL only supports % and _ as wildcards

About the problem:

you use the "=" operatior, whick looks for the value A??
something completely different then "like 'A??'"

So i think you'de need something like

SELECT * FROM member WHERE memberid LIKE 'A%'

But probably, it would be smarter to just split the value up into two values and store them in two columns (will be easier to join, faster to search on, easier to maintain etc ) Specially since the class will probably be quite an important variable.