0

I seem to be having some difficulties with retrieving data from Mysql.

I tried this in PhpMyAdmin SQL:

SELECT *
FROM `ads1`
WHERE state IN ( 'Romania , Germany' )

and the code works but nothing gets returned.

I have a table with value in it and a PHP variable having this format: name1,name2,name3,....,nameN, all in one variable.

Now the idea is that if the table value is contained in the PHP variable, the row get's selected.

Do you guys suggest anything?

1
  • WHERE state IN ('Romania', 'Germany'). Also note that if your database is not case insensitive you will not get results if your search isn't the same case. To be honest, this seems like you're not really up to speed on this, and you'd be better suited reading tutorials. Make sure you read up on SQL Injection attacks and how to prevent them. Commented Jul 26, 2012 at 16:53

1 Answer 1

3
SELECT * FROM ads1 WHERE state IN ( 'Romania' , 'Germany' )

You have to put every entry in quotes and not just the hole input.

Sign up to request clarification or add additional context in comments.

5 Comments

aha , I see , but how do I assign N words to variables and then put those N variables inside the quotes ?
you can fix your formatted variable to the correct format with implode("','", explode(',',$variable))
I am not quite sure wha you wan to achive. Maybe you can add an example to your question.
Well , I have an ads website , which allows the user to choose the states that he wants to see the ads from. The ad will have the state stored in the column xyz , and the user will have a column named stateschoosed which will have all the states that he chooses to see the ads from , like "Romania , Germany , United States of America , Somalia" and so on... . If the state of the ad is among the users choices then the ad gets selected and shown ,I hope you get the idea.
@David Chan , you method worked :D ,that's great man , thank you :) so much :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.