我在这里有一些东西可能真的很容易,但我在过去的 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;
}