Forum Moderators: coopster

Message Too Old, No Replies

problem in matching php variable into mysql data

         

Mohamed

5:05 pm on Dec 1, 2005 (gmt 0)

10+ Year Member



I would like to match php variable into mysql data, I have this code

$query="select DISTINCT artist from music WHERE artist REGEXP '$j'";

the variable does not match any value in mysql data instead the variable take a value from A-Z and match to mysql data.

sorry my english is limited

Anyango

5:15 pm on Dec 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey There

i don't know if i understood your question clearly but try something like this

$query="select DISTINCT artist from music WHERE artist LIKE '$j'";

u want to match artist name like in your variable $j right?

Mohamed

5:27 pm on Dec 1, 2005 (gmt 0)

10+ Year Member



" u want to match artist name like in your variable $j right?"

yes that is what I am trying to achieve?
my variable takes values from A-Z.

Mohamed

5:30 pm on Dec 1, 2005 (gmt 0)

10+ Year Member



"u want to match artist name like in your variable $j right? "

it did not work, it gave me no results as the previous code of mine.

Anyango

5:30 pm on Dec 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes then

"select DISTINCT artist from music WHERE artist LIKE '$j'";

should work fine

Anyango

5:37 pm on Dec 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ah sorry, if that doesn't work, this one should work perfect

"select DISTINCT artist from music WHERE artist LIKE '%$j%'";

sorry forgot to put %% earlier

and if u want this % to work on only one side, for example if u want to find all names starting with A or B or any letter in your variable then it should be like

"select DISTINCT artist from music WHERE artist LIKE '$j%'";

directrix

8:38 pm on Dec 1, 2005 (gmt 0)

10+ Year Member



Another possibility, depending upon your MySQL version, is to use LOCATE. When called as LOCATE(findme, str), this function returns the position of the first occurrence of string findme in string str. It returns 0 if there is no match. (There's also an optional third parameter, which you can use to tell LOCATE the position in str to begin searching.)

So you could try:

$query = "select DISTINCT artist from music WHERE locate('$j', artist) > 0";

Mohamed

1:50 pm on Dec 2, 2005 (gmt 0)

10+ Year Member



thanks all, problem solved.