繁体   English   中英

使user_id等于用户名

[英]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_idtable da_questions等于user_idda_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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM