我在我的代码中使用了mysql_fetch_object,但是得到了一个错误,因为我试图创建的对象有一个构造函数。
错误如下:Warning: Missing argument 1 for Ratio::__construct() in /Users/Alex/Sites/All Good Things/_manage/c/c_ratio.php on line 9
我可以理解;下面是Ratio构造函数的代码:
function __construct($new_name, $new_x, $new_y)
{
$this->name = $new_name;
$this->x = $new_x;
$this->y = $new_y;
}不管怎样,我如何将我刚刚创建的结果中的变量传递给函数,比如,我要做的事情是这样的:
while ($currentRatio = mysql_fetch_object(
$ratio_rs,
'Ratio',
array(
<VALUE OF NAME>,
<VALUE OF X>,
<VALUE OF Y>)))我找不到这第三个参数所需语法的任何示例。
发布于 2012-02-26 09:29:22
使用列别名。列别名取决于构造查询的方式。如果您使用别名(通过as),那么它应该是别名,否则使用列名。参见下面的示例。
$ratio_rs = mysql_query("SELECT Name, x as `X`, y as `Y` from ...");
mysql_fetch_object($ratio_rs,
'Ratio',
array(
'Name',
'X',
'Y'
)
);https://stackoverflow.com/questions/9449695
复制相似问题