Reputation: 61
I have the following code when a user login I want the user profile data pulled from the database to match the user login session variable. How do you get the user profile info thats associated with the user $session_id?
My code snippet:
<?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>
Upvotes: 0
Views: 844
Reputation: 94672
You have a couple of errors in your query!
And once your query works just place the table row output inside the while loop
<?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>';
?>
Its not totally clear where the
info
column lives, i.e. in thegamers
orgamerProfileDate
table. You may need to correct that in the query.
Upvotes: 3