1
$con = mysql_connect("servername","username","password");
        if (!$con){die('Could not connect: ' . mysql_error());}
            mysql_select_db("Appiness", $con);

    $result= mysql_query("SELECT * FROM country");
    while($answer= mysql_fetch_array($result))
    {
        echo $answer;
    }

When i write this it gives me my array of 194 elements but when i echo them it only writes ArrayArrayArray....... 194 times any idea why it is not giving the names of the countries?

3 Answers 3

3

You have to specify which column you want out of your $answer-array. If the column name is name:

echo $answer["name"]
Sign up to request clarification or add additional context in comments.

Comments

2
while($answer= mysql_fetch_array($result))
{
    echo implode("\t", $answer) . "\n";
}

to get all fields, or

while($answer= mysql_fetch_array($result))
{
    echo "$answer[0]\n";
}

to get the first field, etc.

Comments

0

You need to specify the filed that you want to display. mysql_fetch_array returns an array whose key values are the field names from the queried table and whose values are the values in that table for that row.

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.