gpt4 book ai didi

php - 使 user_id 等于用户名

转载 作者:行者123 更新时间:2023-11-29 13:19:23 24 4
gpt4 key购买 nike

我在 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;
}

如何使table da_questions中的user_id等于da_users中的user_id所以当我执行以下操作我会得到正确用户 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

关于php - 使 user_id 等于用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21051296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com