-2

i am trying to echo two values from database and want to echo that value in separate places in html but when i call that function in html it gives me both value in the same place but i want that value in different places how to do that help please.

HTML

    <div id="container">
        <div id="header">
            <a href="home.php?q=logout">LOGOUT</a>
        </div>
        <div id="main-body">
            <br/><br/><br/><br/>
            <h1>
              Hello <?php $user->get_fullname($uid); ?>

              <?php echo $uid; ?>
            </h1>   
        </div>
        <div id="footer"></div>
    </div>

php function in a class name User

    public function get_fullname($uid){
        $sql3="SELECT fullname,uemail FROM users WHERE uid = $uid";
        $result = mysqli_query($this->db,$sql3);
        $user_data = mysqli_fetch_array($result);
        echo $user_data['fullname'];
        echo $user_data['uemail'];

    }
Sheraz
  • 276
  • 1
  • 5
  • 20

1 Answers1

0
    public function get_fullname($uid){
        $sql="SELECT fullname,uemail FROM users WHERE uid = $uid";
        $result = mysqli_query($this->db,$sql);
        $user_data = mysqli_fetch_array($result);
        return (object)array('username'=>$user_data['fullname'],'email'=>$user_data['uemail']);
    }
    /* Call the class method - doesn't echo back to screen */
    $userdata=$user->get_fullname($uid);

Then, later in the code:

echo $userdata->username; 
/* or */
echo $userdata->email

One thing however, perhaps you ought to investigate prepared statements for use with mysqli

Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46