简体   繁体   中英

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'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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