我是一个新手,我以为我以前想通了,但现在我无法正常工作。任何帮助将不胜感激。
表A列出了从表B中提取的用户ID
表B具有链接到上述用户ID的详细信息,例如用户名,姓氏等
我想使用参考的用户名显示用户名
我在站点的不同页面上具有该函数以及该函数的实际调用。
<?php
class Artist {
private $id;
private $artistPic;
private $artistId;
private $artistPrice;
private $owner;
public function __construct($id) {
global $database;
$artist = $database->get('artists', '*', ['id' => $id]);
$this->id = $artist['id'];
$this->artistPic = $artist['artistPic'];
$this->artistId = $artist['id'];
$this->artistPrice = $artist['artistPrice'];
$this->owner = $artist['owner'];
}
static function getLoggedIn() {
global $database;
if( isset($_SESSION['userLoggedIn']) ) {
$artist = $database->get('artists', '*', ['name' => $_SESSION['userLoggedIn']]);
$classArtist = new self($artist['id']);
return $classArtist;
}
}
public function getartistPic() {
return $this->artistPic;
}
public function getArtist() {
return $this;
}
public function getOwnerName() {
global $database;
$owner = $database->get('artists', 'owner', ['id' => $this->getId()]);
return $owner;
}
} ?>
这是当我调用该函数时。但这只是向我显示ID。其他所有尝试都完全错误。
<?php echo $artist->getOwnerName($id); ?>
最佳答案
使用此查询从PHP中的数据库中获取数据,您已经完成了所有工作。
仅从表B获取数据Select tableB.* From tableA INNER JOIN tableB ON tableA.userID = tableB.userID;
仅从表A获取数据Select tableA.* From tableA INNER JOIN tableB ON tableA.userID = tableB.userID;
从两个表中获取数据Select * From tableA INNER JOIN tableB ON tableA.userID = tableB.userID;