开发者

return one value from class

i have one php class

class veh extends dbClass
{
function smo($id)
    {
        $query="select moname from mod where id=".$id;
        $data=$this->query($query,1);
            return $data[0];
    }

}

i am calling that function like this

 $objCms=new veh();
<?=$objCms->smo(1);?>

the 开发者_开发知识库value i got from this is showing array, but i need to get value of moname

Thanks


  1. Your method don't returns anything, you should use return $this->lastQuery; or something like that
  2. You are selecting, but ot fetching results. Try using MySQL Fetch Array or MySQL Fetch Row.

Example code:

class veh extends dbClass
{
function smo($id)
    {
        $query="select moname from mod where id=".$id;
        $this->query($query,1);
        return $this->fetchArray();
    }

}

Where:

  • $this->fetchArray returns result of mysql_fetch_xxx of last query result.


May be the method query return an array as a result, can you give a link to veh class or put query method implementation from veh class.


You would use something like this, depending on how the ->query() method returns it's results. We really need to see ->query()'s body.

function smo($id)
{
    $query = "select moname from mod where id=" . $id;
    $data = $this->query($query,1);
    return $data[0]['moname'];
}

The return statement could be 1 of the following 3 things: $data[0][0], $data[0]['moname'] or $data[0]->moname. You can find out by using var_dump to see how you're able to access the moname column's value.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜