PHP and Mysqli getting value of a count(distinct()) query

前端 未结 3 815
后悔当初
后悔当初 2021-01-26 22:33

I have a db table in mysql called gsm, with 2 columns, LAC and NAME.

So I am trying to count how many different LAC are stored in the DB and retrieve a php value to furt

3条回答
  •  旧巷少年郎
    2021-01-26 23:18

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

提交回复
热议问题