0

Can someone please point out what I'm sure is a stupidly obvious error in my code? The string "string" in my while loop is displaying the correct amount of times but not the results in row[0].

if (!isset($_GET['city']) & !isset($_GET['county'])) {
    $getResults = "SELECT DISTINCT region FROM `locations` WHERE country = 'England'";
    echo "No region or county set";

    if ($result = $mysqli->query($getResults)) {
        echo "Found results";

        while ($row = $result->fetch_assoc()) {
            echo "string";
            echo $row[0];
        }
    }
}
2
  • 1
    In dubious cases, when something is not quite right, remember to use the var_dump() function to echo the variables in question... And then you save yourself valuable time figuring things like this out oon your own. Commented Sep 18, 2013 at 19:01
  • You're fetching assoc but trying to display as though the array is enumerated Commented Sep 18, 2013 at 19:02

2 Answers 2

4

To see the contents of the $row array dump it out like so var_dump($row).

I'm guessing you just need echo $row['region'] rather than $row[0]

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

Comments

2

You are using fetch_assoc() but you try to access the row using a index numbers.

Use fetch_row() instead.

Comments

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.