>HOw 从 php 调用两个值 函数,并将一些值传递给函数
class insert // Class for cheking
{
public function Read($variable)// Read Values From Database
{
//echo $variable;
$read=mysql_query($variable);
$r=""; // Var For Storage Multiple Values
$r1="";
while($res=mysql_fetch_array($read))
{
if($res["Temp"]=="Temp")
{
$r.=$res["Selection"].",";
}
if($res["Temp"]!=="Temp")
{
$r1.=$res["Selection"].",";
}
}// class close
现在我正在调用函数
$data=new insert();
$bar=$data->Read("passing Some MySql Code");
我的问题是如何拨打$r和$r 1温度是我的 MYsql 表中的某个列,我正在检查该 Temp='Temp'其中温度等于或不等于我想读出放
你可以试试这个:
class insert // Class for cheking
{
public function Read($variable)// Read Values From Database
{
//echo $variable;
$read = mysql_query($variable);
$data = array(); // Var For Storage Multiple Values
while($res = mysql_fetch_array($read))
{
if($res["Temp"]=="Temp")
{
$data['one'] .= $res["Selection"].",";
}
if($res["Temp"]!=="Temp")
{
$data['two'] .= $res["Selection"].",";
}
}
return $data;
}
}// class clos
//Call
$data=new insert();
$bar=$data->Read("passing Some MySql Code");
echo("<p>bar:one = ".$bar['one']."</p>");
echo("<p>bar:two = ".$bar['two']."</p>");
好的,
如果我做对了,你想在调用函数后访问r1和r的值。要么将 $r &$r 1 放在数组中并返回它,要么将 $r & $r 1 设置为具有适当 getter & setter 的类属性。
第一种方法
[...]
if($res["Temp"]!=="Temp")
{
$r1.=$res["Selection"].",";
}
return new array("r" => $r, "r1" => $r1);
}// class close
然后
$data=new insert();
$bar=$data->Read("passing Some MySql Code");
echo $bar["r"];
echo $bar["r1"];
第二种方法
class insert // Class for cheking
{
private $r;
private $r1;
public function getR(){
return $this->r;
}
public function getR1(){
return $this->r1;
}
[...]
然后将每次出现的 $r
& $r1
替换为 $this->r
& $this->r1
并像这样使用它
$data=new insert();
$bar=$data->Read("passing Some MySql Code");
echo $data->getR();
echo $data->getR1();