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
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 に答える
0

まず、2 番目の文字列クエリで FROM とテーブルの間にスペースを作成します

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

2 番目 - パブリック プロパティを作成し、必要に応じて名前を付けます。たとえば$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 に答える