Reputation: 23
For some reason I drawing a complete blank on how to display information im looking for from this array. This is the result of this query...
$res = mysql_query("SELECT `key`, `value` FROM `data` where `id` = '4534'", $db_connection);
while ($row = mysql_fetch_assoc($res))
{
print_r($row);
}
result comes out like this
Array ( [key] => am3:id [value] => 5198 )
Array ( [key] => dob [value] => 1984-11-15 )
Array ( [key] => examdate [value] => 1 )
Array ( [key] => howdidyoufind [value] => Facebook )
if I need to place for instance the value of "howdidyoufind" into a variable how would I do that? so the value of the variable would be "Facebook".
Any help would be appreciated, thanks
Upvotes: 0
Views: 1066
Reputation: 780909
Use an if
statement:
if ($row['key'] == 'howdidyoufind') {
$variable = $row['value'];
}
You could also do it in the SQL:
SELECT value
FROM data
WHERE id = 4534 AND key = 'howdidyoufind'
Then the value you want will be in the only row returned by the query.
Upvotes: 5