[英]display array information from sql query
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? 例如,如果我需要将“ howdidyoufind”的值放入变量中,该怎么办? so the value of the variable would be "Facebook". 因此该变量的值为“ Facebook”。
Any help would be appreciated, thanks 任何帮助,将不胜感激,谢谢
Use an if
statement: 使用if
语句:
if ($row['key'] == 'howdidyoufind') {
$variable = $row['value'];
}
You could also do it in the SQL: 您也可以在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. 然后,所需的值将在查询返回的唯一行中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.