我有一个类和一个函数,我想做的是“返回”值并输入另一个函数。
Class test1 {
public function a($x) {
$runquery = "Select * FROM testdb where color_id = '{$x}'";
$result = mysql_query($runquery) or die(mysql_error());
$base_results = mysql_fetch_array($result);
$red = $base_results['red'];
}
public function c($red) {
$runsecond_query = "SELECT * test2db where $color = '{$red}'";
// write additional code
}
好的,我真的想做的是从函数“a”获得结果并在函数“c”中输入结果。我希望这是有道理的。提前感谢任何人。
答案 0 :(得分:1)
function a($x) {
....
return $red;
}
c(a($x));
或者,如果你想要它更清晰一点:
$red = a($x);
c($red);
答案 1 :(得分:1)
由于两个函数都是同一个类的成员,因此您可以创建一个类属性来存储它们:
Class test1 {
// Private property to hold results
private $last_result;
public function a($x) {
$runquery = "Select * FROM testdb where color_id = '{$x}'";
$result = mysql_query($runquery) or die(mysql_error());
$base_results = mysql_fetch_array($result);
// Store your result into $this->last_result
$this->last_result = $base_results['red'];
}
public function c() {
$runsecond_query = "SELECT * test2db where $color = '{$this->last_result}'";
// write additional code
}
}