Reputation: 3514
I have something here that's probably really easy but I've spent the past 30 minutes searching Google without success, so I'm hoping someone can help me with what I'm doing wrong.
I have certain values stores in sessions on the server and I'm trying to retrieve them on a per-user basis to then use in further queries. For some reason however, it's acting as if the value is empty, so I have no idea what I'm doing wrong?
$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;
I'd greatly appreciate any tips on what I'm doing wrong :(
When I do a:
<? print_r($_SESSION['my_country_code']); ?>
It's displayed fine without problems!
//EDIT
Here is the code for 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;
}
Upvotes: 0
Views: 58
Reputation: 12305
Try this:
$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;
Upvotes: 0
Reputation: 909
It looks to me like you're not actually selecting the "country" field (just "id") in your query, but you're trying to access the "country" field. Either select the "country" field or change the second argument of the get_sql_field() call to "id" if that's what you're actually trying to get.
Upvotes: 1