PHP和Mysqli获取count(distinct())查询的值

我在mysql中有一个名为gsm的数据库表,其中有2列LAC和NAME.

因此,我试图计算数据库中存储了多少个不同的LAC,并检索了php值以进一步使用.我正在使用mysqli

我有:

$sql = "select count(distinct lac) from gsm ");

如何将查询存储到php中的变量中?

解决方法:

//conection:
$link = mysqli_connect("www.mywebsite.com","user","password","dataname") or die("Error " . mysqli_error($link));

//consultation:
$query = "SELECT COUNT(DISTINCT alias) as visitors FROM Visits where time BETWEEN timestamp(DATE_SUB(NOW(), INTERVAL 1 HOUR)) AND timestamp(NOW())";

//execute the query.
$result = $link->query($query) or die("Error in the consult.." . mysqli_error($link));
$row = mysqli_fetch_array($result);

//display information:
// The text to draw
$text = $row['visitors'];
上一篇:用 Arduino 步进电机驱动的机械木条时钟


下一篇:nodejs应用接入skywalking实现apm监控(使用阶段)