1

I am trying to select all rows which contains string $places in a colum ADDRESS. here is what I coded but it only works when a cell only contains that string if there is other characters it wouldn't work

$sql = "SELECT *,CONCAT(mapLan,',',mapLon) as LatitudeLongitude FROM " . $table . " where ADDRESS like '$places' and SIZE between $firstrange and $secondrange";

For example $places = "East London" It would only select the row in which a cell only store East London and would leave alone the cells with Old Street, East London

What I want is to select all those rows which contains East London in Column ADDRESS

6
  • 2
    You have to supply an example for your rows and show which you are want to be returned and what do you don't to get them. Commented Feb 4, 2015 at 15:24
  • @sємsєм I want it to return only those rows containing the full string stored in $places for example if it's East London it shouldn't show rows with only East and London but with full phrase East London - Thanks Commented Feb 4, 2015 at 15:33
  • 1
    if $places is East London, the answer I gave you will never return rows that only contain East or London Commented Feb 4, 2015 at 15:36
  • Do not create hypothetical examples if you are having any problem just post the real data, I am sure you will get help. Commented Feb 4, 2015 at 15:51
  • 1
    great, you finally solved it Commented Feb 5, 2015 at 6:17

1 Answer 1

3

You forget to use the % wildcard.

meaning:
% Matches any number of characters, even zero characters

$sql = "SELECT *,CONCAT(mapLan,',',mapLon) as LatitudeLongitude FROM " . $table . " where ADDRESS like '%$places%' and SIZE between $firstrange and $secondrange";

visit this link for detail

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

7 Comments

I have already tried this but it also select the other rows that doesn't exactly contain the required string I just want those rows which contains the exact string stored in $places
@Muhammad No way, I think that %East London% should return any row contains East London.
no, it will not return row that do not contain $places
That is not possible. If $places = "east london" than it will only return the rows containing "east london". Check this demo here: sqlfiddle.com/#!2/c31ae/1
i.e It will not return East Paris
|

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.