douyuan4697 2013-08-29 08:24
浏览 55
已采纳

PHP显示来自mysql的记录

Im blocked at following part of code...

i have config.php page, with following code inside:

<?php
// Start the session (pretty important!)
session_start();

// Establish a link to the database
$dbLink = mysql_connect('localhost', 'USER', 'PASS');
if (!$dbLink) die('Can\'t establish a connection to the database: ' . mysql_error());

$dbSelected = mysql_select_db('DATABASE', $dbLink);
if (!$dbSelected) die ('We\'re connected, but can\'t use the table: ' . mysql_error());

$isUserLoggedIn = false;  
$query      = 'SELECT * FROM users WHERE session_id = "' . session_id() . '" LIMIT 1';  
$userResult     = mysql_query($query);  
if(mysql_num_rows($userResult) == 1){  
$_SESSION['user'] = mysql_fetch_assoc($userResult);  
$isUserLoggedIn = true;  
}else{  
if(basename($_SERVER['PHP_SELF']) != 'index.php'){  
    header('Location: index.php');  
    exit;  
}  
}  
?>

Now i have another page, with following code inside:

<?php include_once('config.php'); ?>

<?php foreach($_SESSION['user'] as $key => $value){ ?>
<li><?php echo $key; ?> <strong><?php echo $value; ?></strong></li>
<?php } ?>

That code show me all informations stored in database, one by one..

I want to show informations, individualy in my page, something like:

<?php echo $email; ?>

etcetera..

Can someone explain me how to do that?

Thank you

  • 写回答

3条回答 默认 最新

  • dpl9717 2013-08-29 08:29
    关注

    You should output it like

    <?php echo $_SESSION['user']['email'] ?>
    

    assuming that 'email' is the column name in the users table.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换