开发者

Fetching variables from database

http://www.srcf.ucam.org/~sas98/e开发者_运维百科nts/index.php

I have a table called ents with a varchar(100) field called week containing the value 'Easter Term 2011, Week 1'. However, the output returns 'Array'.

My code is:

function printWeek() {
    $query = mysql_query("SELECT week FROM ents") or die (mysql_error());
    while ($week = mysql_fetch_array($query, MYSQL_NUM)) {
        echo "$week";
    }
}

Any ideas?


You're calling mysql_fetch_array which returns... wait for it... an array. You need to access the first element of the array if you want an actual value:

echo $week[0];


mysql_fetch_array fetches array of row data (as the name hints), so you have to threat is as such:

function printWeek() {
    $query = mysql_query("SELECT week FROM ents") or die (mysql_error());
    while ($ents = mysql_fetch_array($query, MYSQL_NUM)) {
        echo $ents[0];
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜