tanisha s tanisha s - 3 months ago 5
HTML Question

get column with same name from multiple tables

i have two tables:
USERS(id, name, email, password)
QUESTIONS(id, userid, type, ques, date, time)

i have to pass the value of questions.id as qid.
i am unable to get the desired result with the following code. instead of taking 'id' value of QUESTIONS table, it is taking the 'id' value of USERS table, and therby producing wrong output.


$query = "
SELECT *
, q.id qid
FROM questions q
JOIN users u
ON u.id = q.userid
WHERE type = 'technical'
ORDER
BY date
, time DESC
";
$result = mysqli_query($conn,$query);
while ($row = mysqli_fetch_array($result)) {

$id = $_SESSION['id'];
$ques=$row['question'];
$user = $row['username'];

echo strtoupper($user);

echo "<a href='allview.php?qid=$row[id]' class='class4'> $ques </a>";

}
?>



Answer

Try to use this code

$query = "
SELECT *
     , q.id AS qid,
       q.id AS id
  FROM questions q