2014-01-10 31 views
0

我已经在PHP使USER_ID等于用户名

// 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_questionsuser_id等于在da_usersuser_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; ?> 
+0

所有我能想到当我看到你的查询是“Daaaa熊。” – Jessica

回答

1

你需要一个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 
+1

你是如何从问题中得到的?真正令人印象深刻的心理能力! – Strawberry

相关问题