Php 将json_decode存储在会话变量中

Php 将json_decode存储在会话变量中,php,json,Php,Json,我使用json_encode在表上显示MySQL值。我想将json_encode中的一个值存储到$_会话变量中 以下是我尝试过的: <?php session_start(); include '../../dbconnect.php'; $result = array(); foreach($_SESSION['prod'] as $value) { //echo $value; $rs = mysql_query("select products

我使用json_encode在表上显示MySQL值。我想将json_encode中的一个值存储到$_会话变量中

以下是我尝试过的:

<?php
session_start();
include '../../dbconnect.php';
$result = array();
    foreach($_SESSION['prod'] as $value) {
        //echo $value;
        $rs = mysql_query("select products.product_name as 'product_name', products.product_desc as 'product_desc', order_details.unitcost as 'unitcost', order_details.unitsrp as 'unitsrp', order_details.quantity as 'quantity', order_details.commrate as 'comm', order_details.ma as 'ma', order_details.od_no as 'od_no', `sales-order`.`so-no` as 'sono' from products left join order_details on products.product_id = order_details.product_id left join `sales-order` on order_details.so_number = `sales-order`.`so-number` where order_details.od_no = '$value'");

        while($row = mysql_fetch_object($rs)){
            $result[] = $row;
        }
    }


    echo json_encode($result);
    $data=json_decode($result);
    $qty = $data->quantity;
    $_SESSION['qty']=$qty;

?>
po-grid.php调用get.php来获取数据

问题是,我只是定制了这段代码,您可以查看链接并进行测试,以便理解我的意思,我不确定代码如何将数据从json_编码调用到表单数据进行编辑。我认为他们会在编辑时关联输入名称来调用数据

例如:

将显示一个带有数量值的文本框,即使没有声明它。但我需要的是一个循环下拉列表。不起作用,它有价值,但我需要的是:

<select class="easyui-combobox">
    <?php 
    $qty = $_SESSION['qty']; //this is the part where it calls the variable needed which I'm not sure how to call
    for($x=$qty;$x!=0;$x--)
    {
        echo "<option value='".$x."'>".$x."</option>";  
    }
    ?>
    </select>

如果数量=5,则选项应为5、4、3、2、1。

您没有存储json_编码。你只是在屏幕上回响而已

尝试:


尝试过,但仍有错误:尝试获取非对象的属性。:/抱歉,如果无法访问数据,我无法很好地测试它。你能发布一些经过消毒的测试数据吗?尝试打印目标定义变量;在回显json_encode$结果之前;向我们展示当您使用json_encode时您的代码是什么样子的为什么将其存储在$_会话中?我需要另一个页面中的特定数据。这些数据存在于您的数据库中。你可以再次得到它,我真的不想再查询了。我的代码不是这样工作的。这真的很难解释。好吧,在不知道背景的情况下很难说,但这听起来是一种糟糕的做法
<select class="easyui-combobox">
    <?php 
    $qty = $_SESSION['qty']; //this is the part where it calls the variable needed which I'm not sure how to call
    for($x=$qty;$x!=0;$x--)
    {
        echo "<option value='".$x."'>".$x."</option>";  
    }
    ?>
    </select>
$encoded_results = json_encode($result);
echo $encoded_results;

$data = json_decode($encoded_results);