我是否可以获得有关提取用户名字和指南的指导方面的帮助。另一个表中的姓氏我已经调用成员来显示我已经从一个名为folio的表中显示的信息中的数据,这个代码中我需要添加JOIN的任何想法?
见下文:
<div id="latest">
<?php
$query = 'SELECT * FROM folio ORDER BY dateadded DESC';
$result = mysqli_query($connection, $query);
if(!$result){
die('Database error: '.mysqli_error($connection));
}
while($row = mysqli_fetch_assoc($result)){
?>
<div class="outimgbox"> <a style="text-decoration: none;" href="temp.php?imgid=<?php echo $row['imgid']; ?>">
<div id="mainwrapper">
<div id="box-3" class="box"> <img class="uploads" src="uploads/folio/<?php echo $row['filename']; ?>" /> <span class="caption fade-caption">
<h3><?php echo $row['title']; ?></h3>
<p style="color: #2d2d2d; font-size: 12px; padding-left:2px; padding-top:2px; margin-top: 16px; text-decoration: none;"><?php echo $row['description']; ?></p>
</span></div>
</div>
</a>
</div>
答案 0 :(得分:0)
在查询中使用JOIN
:
SELECT f.*, m.firstname, m.lastname
FROM folio f
INNER JOIN members m ON f.userid = m.id
ORDER BY f.dateadded DESC
答案 1 :(得分:0)
您可以执行以下操作,具体取决于members
表中列名称的内容:
$query = 'SELECT f.*, m.firstname AS firstname, m.lastname AS lastname FROM folio AS f, members AS m WHERE f.userid = m.id ORDER BY dateadded DESC';
然后
$row['firstname'] // first name
$row['lastname'] // last name