用户登录时我有以下代码我希望从数据库中提取用户配置文件数据以匹配用户登录会话变量。如何获取与用户$ session_id相关联的用户个人资料信息?
我的代码段:
<?php
bin2hex(openssl_random_pseudo_bytes(32));
include('inc/database.php');
include('session.php');
$userDetails=$userClass->userDetails($session_id);
$db = getDB();
$sql = "SELECT
gamerEmail
, gamerContent
,p.gpd_id
, p.content
FROM gamers g
INNER JOIN
gamerProfileData p
where gamers.gamer_id = gamerProfileData.gpd_id ;
ORDER BY gamer_id = {$_SESSION['gamer_id']}, gpd_id";
$gamer_profile = $db->query($sql);
foreach ($gamer_profile as $gamer_info) {
$gamer_info['something']; //I'm stuck....
?>
<tr>
<td>Gamer Profile ID: <?php echo $gamer_info['gpd_id'] ?> </td>
<td>Gamer Profile Info: <?php echo $gamer_info['info'] ?> </td>
</tr>
答案 0 :(得分:3)
您的查询中有几处错误!
一旦你的查询工作,只需将表行输出放在while循环
中<?php
bin2hex(openssl_random_pseudo_bytes(32));
include('inc/database.php');
include('session.php');
$userDetails=$userClass->userDetails($session_id);
$db = getDB();
$sql = "SELECT gamerEmail, gamerContent, p.gpd_id, p.content, p.info
FROM gamers g
INNER JOIN gamerProfileData p ON gamers.gamer_id = gamerProfileData.gpd_id
WHERE gamer_id = {$_SESSION['gamer_id']}
ORDER BY gpd_id";
$gamer_profile = $db->query($sql);
echo '<table>';
foreach ($gamer_profile as $gamer_info) {
?>
<tr>
<td>Gamer Profile ID: <?php echo $gamer_info['gpd_id'] ?> </td>
<td>Gamer Profile Info: <?php echo $gamer_info['info'] ?> </td>
</tr>
<?php
} // endwhile
echo '</table>';
?>
info
列的所在位置不明确,即gamers
或gamerProfileDate
表。您可能需要在查询中更正它。