0

Tengo una serie de tablas las cuales tienen información para rellenar mi highchat. El problema es que no he logrado generar el código para traer de la base de datos esa información:

   $command = $connection->createCommand('SELECT idClient,name,country,image 
  FROM client');

  $posts = $command->queryAll();

 $nameClient = array_column($posts, 'name');
   //print_r($nameClient);

    foreach ($nameClient as $key => $value) {
   $arrayName[] = $nameClient[$key];
   }
 //  print_r($arrayName);
$connection->open();
$count = $connection->createCommand('SELECT count(name),name FROM client');
$numt = $count->queryOne();


  # code...
 //$numClients['num'] = 1;
foreach ($posts as $key => $value) {




 # code...
  $getIdIssues= $connection->createCommand('SELECT name,idissuetype as 
  idissues FROM issuetype');
 $idIssues = $getIdIssues->queryAll();




 //$nameIssue = $queryGetName->queryOne();





 foreach ($idIssues as $key1 => $value1) {
# code...
  //print_r($dataLista);

$queryDataClientes=  $connection->createCommand("SELECT DISTINCT
 iss.name AS '0', COUNT(*) AS '1'
  FROM
issues AS isu,
project AS pr,
client AS cl,
issuetype AS iss
  WHERE
isu.project_idproject = pr.idproject
  AND cl.idclient = pr.client_idclient
  AND cl.idclient = ".$value['idClient']."
  AND iss.idissuetype = isu.issuetype_idissuetype
  AND iss.idissuetype = ".$value1['idissues']."
GROUP BY
issuetype_idissuetype
 HAVING
COUNT(*) >= 0
 ORDER BY issuetype_idissuetype;");


 $dataClientesQuery = $queryDataClientes->queryOne();





echo "<pre>";

 $dataClientesQuery['1'] = (empty($dataClientesQuery['1'])) ? 0 : 
 (int)$dataClientesQuery['1'] ;
$dataLista[$key]['data'][]= (int)$dataClientesQuery['1'] ;
}

}
print_r($dataLista);

Así queda:

 Array
  (
     [0] => Array
         (
            [data] => Array
              (
                [0] => 1
                [1] => 0
                [2] => 0
            )

    )

   [1] => Array
    (
        [data] => Array
            (
                [0] => 2
                [1] => 3
                [2] => 0
            )

    )

   [2] => Array
    (
        [data] => Array
            (
                [0] => 1
                [1] => 0
                [2] => 0
            )

    )

  [3] => Array
    (
        [data] => Array
            (
                [0] => 1
                [1] => 0
                [2] => 0
            )

      )

 )

Así tiene que quedar tomando en cuenta que la cantidad tienen que ordenarse por issues:

 Array
(
    [0] => Array
      (
        [name] => Historias
        [data] => Array
            (
                [0] => 10
                [1] => 7
                [2] => 3
                [3] => 4
                [4] => 7
            )

       )

     [1] => Array
    (
          [name] => Defectos
           [data] => Array
              (
                [0] => 5
                [1] => 7
                [2] => 3
                [3] => 4
                [4] => 7
              )

       )

  )

Para mas información por favor indicar.

2
  • Qué variable es esa a la que le estás haciendo print?
    – Sr1871
    Commented el 10 oct. 2018 a las 15:08
  • esta hermano print_r($dataLista); Commented el 10 oct. 2018 a las 15:09

1 respuesta 1

0

Solo te falta agregar el indice de name

foreach ($idIssues as $key1 => $value1) {
   # code...
  //print_r($dataLista);

  $queryDataClientes=  $connection->createCommand("SELECT DISTINCT
    iss.name AS '0', COUNT(*) AS '1'
  FROM
    issues AS isu,
    project AS pr,
    client AS cl,
    issuetype AS iss
  WHERE
    isu.project_idproject = pr.idproject
    AND cl.idclient = pr.client_idclient
    AND cl.idclient = ".$value['idClient']."
    AND iss.idissuetype = isu.issuetype_idissuetype
    AND iss.idissuetype = ".$value1['idissues']."
  GROUP BY
    issuetype_idissuetype
  HAVING
  COUNT(*) >= 0
  ORDER BY issuetype_idissuetype;");

  $dataClientesQuery = $queryDataClientes->queryOne();

  echo "<pre>";

  $dataClientesQuery['1'] = (empty($dataClientesQuery['1'])) ? 0 : 
    (int)$dataClientesQuery['1'] ;
  $dataLista[$key]['data'][]= (int)$dataClientesQuery['1'] ;

  if(!isset($dataLista[$key]['name'])){
    $dataLista[$key]['name'] = $dataClientesQuery['0'];
}

Aquí el isset es para verificar si la variable existe, así se evita estar asignándola en cada for.

Como consejo, a mi parecer con tantos for haces demasiadas llamadas a la BD si optimizas tu consulta quizá puedas traerte todo en una sola para no andar haciendo una por una

2
  • amigo gracias por el cambio por que aun no resuelve el problema necesito colocar cada tipo de issue a cada array Commented el 10 oct. 2018 a las 15:39
  • no se si me hago entender Commented el 10 oct. 2018 a las 15:39

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.