-2

When I run the code below it does work

$sql = "SELECT * FROM `be_22122020` WHERE 1";


$result = $conn->query($sql);

while($row = $result->fetch_assoc()) {
echo "id: " . $row["code"]. " - Name: " . $row["airport_name"]. " " . $row["country_code"]."<br>";
}

But when I change the MYSQL query into the code below the pages shows an

AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to a member function fetch_assoc() on bool

$sql = "SELECT `code`, `airport_name`, `country_code` FROM `be_22122020` WHERE code = 
\'JFK\'";

The MYSQL query is copied from phpMyAdmin and is should work. How can I fix this error so it echo's the correct values?

Dharman
  • 30,962
  • 25
  • 85
  • 135
stevv
  • 51
  • 7
  • Please check for the error that caused the result to be a bool. Follow advice here: https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param – Bill Karwin Dec 25 '20 at 17:27
  • There is no need to escape single quotes when they're inside double quotes. – El_Vanja Dec 25 '20 at 17:35

1 Answers1

-1

I think your query is wrong. Try something like this:

$sql = "SELECT * FROM be_22122020 WHERE code = 'JFK'";
mrSotirow
  • 103
  • 1
  • 4
  • Thanks, did the trick. – stevv Dec 25 '20 at 19:06
  • When you are selecting an specific row you need to add WHERE clause = value like in this case you want to select all rows with code 'JFK' you can also add limit with LIMIT 5. – mrSotirow Dec 25 '20 at 19:17