簡體   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