Querq mysql html

0

I have a query that is this

SELECT COUNT(id_orden) as cuantas FROM 'orden_trabajo' ORDER BY status

this gives me a result of

cuantas
46

my problem is that I can not pass this result of the query to an html. my idea was to pass it to a function like this

function total(){
include("dbconnect.php");
$total=0;
$sql = $conn->prepare("SELECT orden_trabajo.status, COUNT(id_orden) AS
cuantas FROM orden_trabajo ORDER BY status ");
$sql->execute();
if ($sql->rowCount () > 0){
while($total=$sql->fetch(PDO::FETCH_ASSOC))
{
return $total['no_reporte']; 
  }
 }else{
return "NA";
 }
}
    
asked by Eddy Olvera 31.01.2018 в 18:40
source

1 answer

0
  

We assume that the connection to your data base is correct and that the file dbconnect.php works well.

In this part:

$sql = $conn->prepare("SELECT orden_trabajo.status, COUNT(id_orden) AS

how many FROM order_work ORDER BY status ");

you select orden_trabajo.status and COUNT(id_orden) (you rename it cuantas ) and then return no_reporte :

return $total['no_reporte'];

that variable ( no_reporte ) does not exist. That's why nothing returns. Modify it by

return $total['cuantas'];
    
answered by 31.01.2018 / 18:53
source