数据存储在会话中,但在其他 php 文件中获取时,某些对象为空 [英] Data stored in Session but when fetch in other php file some objects is null
本文介绍了数据存储在会话中,但在其他 php 文件中获取时,某些对象为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我将数据存储在会话数组中的原始位置上,当我获取它时所有数据都是完整的,但是当我在另一个会话上调用该会话时,一些数据为空或未定义.
On the original where I stored the data in session array, all data are complete when I fetch it but when I call that session on the other some data is null or undefined.
我不知道我要做什么,请帮忙
I don't know what I'm going to do, please help
在原始文件中
$query = $dbh->prepare("Select p.start_date,p.end_date,dfp.id,dfp.product_id
dfp.type,dfp.quantity_required,dfp.less,pd.unit,pd.name
from promo p
inner join discounts_free_products dfp
on p.id=dfp.promo_id
inner join products pd
on dfp.product_id=pd.id
where DATE(p.end_date) >= DATE(NOW())
");
$query->execute();
$count=0;
$queryresult_set=array();
$queryresult_set=$query->fetchAll();
$count=count($queryresult_set);
$_SESSION['COUNT_PROMO']= $count;
$_SESSION["PROMO_PRODUCTS"]=$queryresult_set;
在其他php文件中
foreach($_SESSION["PROMO_PRODUCTS"] as $result) {
$pc_list[] = $result["product_id"];
$d_id=$result['id'];
}
错误:未定义索引:product_id
error:Undefined index: product_id
推荐答案
会话使用 session_start()
函数启动.
A session is started with the
session_start()
function.
会话创建
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
?>
</body>
</html>
在另一个页面上检索会话
To retrieve session on another page
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Echo session variables that were set on previous page
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
?>
</body>
</html>
这篇关于数据存储在会话中,但在其他 php 文件中获取时,某些对象为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文