我一直在尝试以如下格式动态传递字段名称和表名称:
       function GetTBL($TBL, $FIELDS) 
       {
           ........
           $query = "SELECT $FIELDS FROM $TBL ";
           .....
           ......
        }
但我不知道如何调用该函数以及如何使用它?请帮我。
尝试这个
你的功能
    function GetTBL($table,$fields = "*",$limit=10){
        $sql = "SELECT $fields FROM $table  LIMIT $limit";
        $result = mysql_query($sql);
        return $result;
}
在调用此函数时,您必须传递参数
例子
$table="mytable";
$fields=" myname,mysurname ";
$result=GetTBL($table,$fields); // other parameters take  default value if you not pass value
您可以根据您的要求通过传递其他参数来使此函数更可重用 condition , orderby 等。
如果您的表名为“mytable”且字段为“myfield”
像这样称呼它
$results = GetTBL($mytable, $myfield);