简体   繁体   English

使user_id等于用户名

[英]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_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; ?>

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.

相关问题 如何以多行形式保存用户名和user_id - how to save username and user_id in multiple row form Laravel从另一个表中基于user_id获取用户名 - Laravel Get Username based on user_id from another table 如何从laravel 5.3上的user_id获取用户名? - how to get username from user_id on laravel 5.3? 如何在URL中添加用户名而不是cakephp 3中的user_id - how to append the username in url instead of user_id in cakephp 3 尝试使用 user_id Laravel 从用户模型中获取用户名 - Trying to get username from User model using user_id Laravel 我想显示评论所有者的用户名,但是评论表仅具有user_id - I want to display username of comment's owner, however, comments table has user_id only 如何从其他表中的 user_id 存储在其他表中获取用户名 - How to fetch username from other table user_id store in other table 当模型与user_id关联时,symfony管理员列表视图按用户名排序 - symfony admin list view Sort by username when the model is associated with user_id 如何在不使用authKeys和accesstoken的情况下获取任何用户名或user_id的Twitter关注者列表 - How to get twitter followers list of any username or user_id without using authKeys and accesstoken 选择从user_id到user_id的消息 - Selecting messages from user_id to user_id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM