简体   繁体   English

如何在php中显示MySQL查询的结果?

[英]How to display the results of a MySQL query in php?

I have this function in a linked file: 我在链接文件中具有此功能:

function getIndividualHerpInfo($herpID) {
    $sql = "SELECT COLOR, PRICE
    FROM HERPES
    WHERE ID = $herpID";
    return DBIface::connect()->query($sql)->fetch(PDO::FETCH_ASSOC);
}

I can call on this function from any other page in the website. 我可以从网站上的任何其他页面调用此功能。 What I want to do is to be able to use the results of this query individually. 我要做的是能够单独使用此查询的结果。 Like, echo the color of one herp, and, in another place, echo the price of the herp. 就像,回荡一个人的疱疹的颜色,而在另一个地方,回荡人的疱疹的价格。

I tried looking online for how to do this, but I was unable to find something to help me with the structure of this particular function. 我曾尝试在网上寻找如何执行此操作,但无法找到有助于该特定功能结构的内容。 Please tell me how to use the results of such a query individually in another file? 请告诉我如何在另一个文件中单独使用这样的查询结果? Thanks. 谢谢。

like this 像这样

$data = getIndividualHerpInfo(1);

echo $data['COLOR'];
echo $data['PRICE'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM