0

我在这里有一些东西可能真的很容易,但我在过去的 30 分钟里搜索谷歌没有成功,所以我希望有人能帮助我解决我做错的事情。

我在服务器上的会话中存储了某些值,我试图按每个用户检索它们,然后在进一步的查询中使用。然而,出于某种原因,它的行为就好像值是空的,所以我不知道我做错了什么?

$session_country = $_SESSION['my_country_code'];
$user_country = $db->get_sql_field("SELECT id FROM db_countries WHERE country_iso_code='".$session_country."'","country");
echo "your country is ";
echo $user_country;

对于我做错的任何提示,我将不胜感激:(

当我做一个:

<? print_r($_SESSION['my_country_code']); ?>

它显示得很好,没有问题!

//编辑

这是 get_sql_field 的代码:

function get_sql_field ($query, $field, $null_message = NULL)
    {
            (string) $field_value = NULL;

            $query_result = $this->query($query);

            if ($this->num_rows($query_result))
            {
                    $field_value = $this->sql_result($query_result, 0, $field);
            }
            else
            {
                    $field_value = $null_message;
            }

            return $field_value;
    }
4

2 回答 2

1

在我看来,您实际上并没有在查询中选择“国家”字段(只是“id”),但您正在尝试访问“国家”字段。要么选择“国家”字段,要么将 get_sql_field() 调用的第二个参数更改为“id”,如果那是你真正想要得到的。

于 2013-11-05T21:00:53.757 回答
0

尝试这个:

$session_country = $_SESSION['my_country_code'];
$qry = "SELECT country FROM db_countries WHERE  country_iso_code='".$session_country."'";
$user_country = $db->get_sql_field($qry,"country");
echo "your country is ".$user_country;
于 2013-11-05T21:06:58.613 回答