I have the following code in 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.
<?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
SELECT *
FROM da_questions
INNER JOIN da_users ON da_users.user_id = da_questions.user_id
ORDER BY da_questions.question_id DESC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.