开发者

How to access elements of the return value of mysql_fetch_array?

$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 $ans开发者_运维问答wer;
    }

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?


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

echo $answer["name"]


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜