Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用oop php以html格式显示特定于用户的数据_Php_Oop - Fatal编程技术网

使用oop php以html格式显示特定于用户的数据

使用oop php以html格式显示特定于用户的数据,php,oop,Php,Oop,我想显示一个特定于用户的表单,其中包含他的个人详细信息,然后允许他更新这些信息。但为了做到这一点,首先我需要在表格中显示他的详细信息,以便他可以更新它们 我在MyClass类中有一个函数ShowUserInformation(): function ShowUserInformation() { $query = "SELECT id, name, email FROM saloni WHERE id = '$_SESSION[ID_korisnika]'"; $result =

我想显示一个特定于用户的表单,其中包含他的个人详细信息,然后允许他更新这些信息。但为了做到这一点,首先我需要在表格中显示他的详细信息,以便他可以更新它们

我在MyClass类中有一个函数ShowUserInformation():

function ShowUserInformation()
{
    $query = "SELECT id, name, email FROM saloni WHERE id = '$_SESSION[ID_korisnika]'";
    $result = mysql_query($query);
    while($row=mysql_fetch_array($result)):
        $id= $row['id'];
        $name= $row['name'];
        $email = $row['email'];
    endwhile;   

    return $result;
}   
我的问题是:如何在文本框的另一页上显示$name、$email或$id的值

如果我以程序化的方式进行,那么在我进行此操作时,它会起作用:

<input type="text" value="<?php echo $name ?>" name="name" class="" />
HTML-我试过这样的东西

<input type="text" value="<?php echo $my_class->ShowUserInformation($name)?>" name="name" class="" />

ShowUserInformation()函数必须返回$name。在您编写的代码中,函数返回$result

HTML必须是这样的:

<input type="text" value="<?php echo $my_class->ShowUserInformation() ?> name="name" class="" />
快速肮脏的方式:

class YourClass {

    /**
     * Ident
     */
    public $id;

    /**
     * Name
     */
    public $name;

    /**
     * Mail
     */
    public $email;

    public function showUserInformation($name) {

        //[...]        

        while($row=mysql_fetch_array($result)):
            $this->id= $row['id'];
            $this->name= $row['name'];
            $this->email = $row['email'];
        endwhile; 

        //[...] 

    }
}


<input type="text" value="<?php echo $my_class->name?>" name="name" class="" />
classyourclass{
/**
*识别
*/
公费$id;
/**
*名字
*/
公共名称;
/**
*邮寄
*/
公费邮件;
公共函数showUserInformation($name){
//[...]        
而($row=mysql\u fetch\u array($result)):
$this->id=$row['id'];
$this->name=$row['name'];
$this->email=$row['email'];
结束时;
//[...] 
}
}

谢谢你的回答,但是我怎么能在不声明它们为类变量的情况下调用它呢,因为有很多行,我刚刚把代码缩短了三行。谢谢你的回答,但是我会有更多的文本字段,所以我不能只返回一个值。我需要它以某种方式返回值,这样我就可以在HTMl$name或$email$phone中更改,因为我将在查询中有更多的行,我只是在我发布的代码中显示了三行。
class YourClass {

    /**
     * Ident
     */
    public $id;

    /**
     * Name
     */
    public $name;

    /**
     * Mail
     */
    public $email;

    public function showUserInformation($name) {

        //[...]        

        while($row=mysql_fetch_array($result)):
            $this->id= $row['id'];
            $this->name= $row['name'];
            $this->email = $row['email'];
        endwhile; 

        //[...] 

    }
}


<input type="text" value="<?php echo $my_class->name?>" name="name" class="" />