1

I have a table that stores cities

id | city         | player 
1  | Miami        | Mark
2  | Miami Beach  | Tiffany
3  | New York     | John
4  | Boston       | Bette
5  | Boston       | Laura

I have a query that selects the city according to input

$select = $conn->prepare("SELECT player FROM game_table WHERE city LIKE=?");
$select->bind_param("s", $city);
$select->execute();
$select->close();

How do I use the query with a prepared statement and select everyone from the same city? Miami should return 2 players. How can I make sure the system recognizes Miami Beach as part of Miami?

Grogu
  • 2,097
  • 15
  • 36
  • 1
    Your query is missing the quotes resulting in a parse error. – Funk Forty Niner Feb 22 '20 at 00:31
  • @FunkFortyNiner: I forgot to put them in here they are alright in my codes.. Edited my question. – Grogu Feb 22 '20 at 00:37
  • @SaturnConjuction I see you figured this out. I updated my answer to remove the equal sign. – jdavid05 Feb 22 '20 at 00:43
  • 2
    Ok @SaturnConjuction Remove the `=` in this `LIKE=?`. – Funk Forty Niner Feb 22 '20 at 00:45
  • @FunkFortyNiner: For some reason it does not work. I receive a MYSQL syntax error. – Grogu Feb 22 '20 at 00:49
  • @SaturnConjuction Ooops, I left something out because it's been a while since I've used LIKE. See [this answer](https://stackoverflow.com/a/18527848/1415724) in another post here on Stack. – Funk Forty Niner Feb 22 '20 at 00:50
  • @FunkFortyNiner : Thank you very much. You can mark this as duplicate. Sorry for this :-S – Grogu Feb 22 '20 at 00:52
  • @SaturnConjuction Welcome. I would but I already cast my vote as unclear :( due to the missing quotes earlier. – Funk Forty Niner Feb 22 '20 at 00:53
  • 1
    Be sure you use '%' prefix/sufix in the search criteria as city LIKE 'Miami' is the same as city = 'Miami'. if you want to find both Miami and Miami Beach yo need to specify city LIKE 'Miami%'. – MaxT Feb 22 '20 at 00:54
  • Does this answer your question? [php mysqli prepared statement LIKE](https://stackoverflow.com/questions/18527659/php-mysqli-prepared-statement-like) – Dharman Feb 22 '20 at 09:35

0 Answers0