gpt4 book ai didi

php - 如何从连接表结果中具有相同名称的两个值中获取单个值?

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

我运行以下查询并获得结果:

The print view

现在,如果我运行以下命令,那么我得到的 user_id 为 0。

<?php 
session_start();
require_once('connectvars.php');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

$user_id = $_SESSION['user_id'];

$result = mysqli_query($dbc,"SELECT * FROM `user_question`join question WHERE user_question.qid = question.qid and user_question.user_id = $user_id")
or die("Error in fetching the value.");

while ( $row = mysqli_fetch_array($result))
{
echo 'user id : ';
echo $row['user_id'];
echo "<br>";
echo 'qid: ';
echo $row['qid'];
echo "<br>";
echo 'answer_key: ';
echo $row['answer_key'];
echo "<br>";

}


?>

如何获取 user_id : 4 ?

最佳答案

您可以按如下方式进行:

$result = mysqli_query($dbc,"SELECT user_question.user_id,user_question.qid,user_question.answer_key FROM `user_question`join question WHERE user_question.qid = question.qid and user_question.user_id = $user_id")

现在 echo $row['user_id']...

关于php - 如何从连接表结果中具有相同名称的两个值中获取单个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25342213/

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