[英]make user_id equal to username
I have the following code in php 我在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;
}
How can I make the user_id
in table da_questions
be equal to the user_id
in da_users
so when I do the following I get the correct username for the correct user id. 我怎样才能让
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; ?>
You need a ON
condition in your join 您的加入需要
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.