Show in PHP a query that is done directly in phpMyAdmin

Asked

Viewed 64 times

1

I have a query ready (I didn’t do it) that every month I change the values of the months, copy and paste in phpMyAdmin (in the SQL tab) to run. She presents me with a very beautiful and structured answer in columns. But how do I make the same answer directly in PHP?

The query is this:

SET @date_ini = '2019-02-20 00:00:00';
SET @date_end = '2019-03-19 23:59:59';
SELECT DISTINCT(`dstchannel`) as Canal,
count(1) as qtde,
SUM(IF(billsec< 30, 30, ((`billsec` DIV 6) * 6) + (IF(`billsec` % 6 > 0,6,0)))) as Segundos ,
sum(IF(billsec > 30,1,0)) as qtde_maior30,
SUM(IF(billsec > 30, ((`billsec` DIV 6) * 6) + (IF(`billsec` % 6 > 0,6,0)),0)) as Segundos_maior30
FROM astcdr.cdr WHERE `dstchannel` LIKE 'Khomp/B%' AND `calldate` BETWEEN @date_ini AND @date_end and billsec > 3 GROUP BY Canal ;

And the answer phpMyAdmin shows is this:

inserir a descrição da imagem aqui

1 answer

2

Dude, you’re going to have to create a table in html, and pull the data that came from select through a While, after that and just structure the data in the table that they get "Cute" haha.

Come on:

To create the connection use this:

$con = new mysqli($Conexao, $User $Senha, $Database))

$Conexao = localhost (no teu caso) $Database = Nome da tua base de dados...

This Executes the Query for you:

$consulta = "SUA QUERY";
$resultado = $con->query($consulta );

With this While you take the data that your query Returned:

while($row = $resultado->fetch_assoc()) {
        echo "Dado: ".$row["dado"].";";
 }

From this you could create a table inside php, Example:

echo "<table>"
  echo "<tr>"
    echo "<td>".$row["dado"]."</td>"
  echo "</tr>"
echo "</table>"

Then just create the table with the data you want.

  • I just don’t know the name of the fields over there where $Row['given']!

  • is the same name as on the table

Browser other questions tagged

You are not signed in. Login or sign up in order to post.