0
class.php

class Database {

function select_user($formation,$department,$table) 
{

if(($formation=="Select All") and ($department=="Select All"))
    {
    $select_user=mysql_query("SELECT * FROM ". $table . "  order by dateofjoin DESC");
    echo "SELECT * FROM ". $table ." order by dateofjoin DESC";
    }
    else
    {
    $query="SELECT * FROM". $table ." WHERE formation='$formation' and department='$department' order by dateofjoin DESC";
    //echo "SELECT * FROM ". $table ." WHERE formation='$formation' and department='$department' order by dateofjoin DESC";
    return ($query);
    }

}

在 viewtudent.php 中,我正在为类似的函数争论

$obj= new Database;
 $obj->select_user($_POST['formation'],$_POST['department'],'user');

所以请告诉我如何从 class.php,,thx,,, 中获取值

4

3 回答 3

0
include("class.php");
$obj= new Database;
$obj->select_user($_POST['formation'],$_POST['department'],'user');

包括class.php为了使用该文件中的类。

于 2013-11-15T11:30:45.750 回答
0

首先在第二个字符串查询中在 FROM 和表之间留出空间

$query="SELECT * FROM ". $table ." WHERE formation='$formation' and department='$department' order by dateofjoin DESC";

第二 - 创建公共属性,并根据需要命名,例如$class_var,然后将此属性设置为类,您可以从类中获取值:

class Database {

    public $class_var;

    function select_user($formation,$department,$table) 
    {
           $this->class_var->{any_property_or_method};
     //.....
    }
}

include("class.php");
$class = new Class();
$db= new Database();
$db->class_var = $class;
$db->class_var->{whatever_in_class}
$db->select_user($_POST['formation'],$_POST['department'],'user');
于 2013-11-15T11:47:57.387 回答
0
you have made some changes there is change in first if statement ...


if(($formation=="Select All") and ($department=="some department name"))
{
$select_user=mysql_query("SELECT * FROM ". $table . "  order by dateofjoin DESC");
echo "SELECT * FROM ". $table ." order by dateofjoin DESC";
}
于 2013-11-15T11:32:42.487 回答