[英]make user_id equal to username
我在PHP中有以下代碼
// Get all the questions
$query = mysqli_query($con, "SELECT * FROM da_questions INNER JOIN da_users ORDER BY da_questions.question_id DESC");
$allquestions = array();
while($row = mysqli_fetch_array($query))
{
$allquestions[] = $row;
}
我怎樣才能讓user_id
在table da_questions
等於user_id
在da_users
所以當我這樣做,我得到了正確的用戶ID正確的用戶名。
<?php foreach($allquestions as $question): ?>
<span><b><?php echo $question['question_title']; ?><span class="pull-right"><?php echo $question['username']; ?></span></b></span>
<hr style="margin-top:0px;" />
<p><?php echo $question['question_text']; ?></p>
<?php endforeach; ?>
您的加入需要ON
條件
SELECT *
FROM da_questions
INNER JOIN da_users ON da_users.user_id = da_questions.user_id
ORDER BY da_questions.question_id DESC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.