Report everything, without id

0

Previously I had made a report in pdf where I brought everything that belonged to a folio , I had no problem in that, since identifying the number already came with their respective information.

On this occasion I want to do another pdf , but this is not linked to any page or id , simply, by pressing the button generate report, will bring the data. and I'm confused on how to do that, that shows everything in pdf without being dependent on an identifier.

This code is the first pdf that was made:

  if(isset($_GET['folio']))
  {
    $folio = $_GET["folio"];
    $connection = new MySqlServerConnection();
    //consulta fea
    $query = 'SELECT folio, totalQty, totalPrice as precio, a.author as elaborado, authorizateBy, assignmentDate, ep.employeeNumber, ep.name as solicitante, ep.position as posicion, ei.employeeNumber,
              ei.name as cargo, ei.position, d.id, d.name,c.id , c.name as company, ad.supplies_id, ad.supplies_price, ad.supplies_name as nomarti, ad.qtySupply as cant, s.image as imageeen,
              s.brand as marca, s.model as modelo, s.id as sid, s.quantity, s.price as price
              FROM Assignments as a
              INNER JOIN Employees as ep ON ep.employeeNumber = a.employee_Petitioner
              INNER JOIN Employees as ei ON ei.employeeNumber = a.employee_InCharge
              INNER JOIN Departaments as d ON d.id = a.department_id
              INNER JOIN Companies as c ON c.id = d.company_id
              INNER JOIN AssigmentsDetail as ad ON ad.assignments_folio = a.folio
              INNER JOIN Supplies as s ON s.id = ad.supplies_id
              WHERE folio = ? AND ad.status = 1';
    $result = $connection->executeQuery($query, array($folio));
    // $arraySupplies = array();

    if ($result >0)
    {...}

As you can see it identifies the folio and simply generated the pdf with the requested data.

This is the code of the current pdf:

  if(isset($_GET['x']))
    {
      $x = $_GET["x"];
      //Trae todos los item que esten por debajo de su minimo en stock.
      $connection = new MySqlServerConnection();
      $query = 'SELECT i.description_item,i.quantity,u.name_unit,i.reorder_Level,i.target_Stock,l.name_location,i.commentt
      FROM inventory_list AS i
      INNER JOIN unit_mesurement AS u ON id_unit = fkUnit
      INNER JOIN locatiON AS l on id_location = fkLocation
      WHERE i.quantity <= reorder_Level AND i.status = 1';

      $result = $connection->executeQuery($query,array($x));
      if ($result > 0) {...}

My problem is that I do not know how to only generate it without being linked to a id , I would like to remove the if(isset($_GET['x'])) since that will not be necessary and in my where I do not say that in case of being any id , show me the data.

I hope you have explained me, and you can help me.

    
asked by Pato 05.12.2018 в 23:30
source

2 answers

0

simply leave the following code:

$connection = new MySqlServerConnection();
$query = 'SELECT i.description_item, i.quantity, u.name_unit, i.reorder_Level, i.target_Stock, l.name_location, i.commentt
FROM inventory_list AS i
INNER JOIN unit_mesurement AS u ON id_unit = fkUnit
INNER JOIN locatiON AS l on id_location = fkLocation
WHERE i.quantity <= i.reorder_Level AND i.status = 1';

$result = $connection->executeQuery($query);

if ($result > 0) {...}

It would be necessary to see if the "executeQuery" method of the class "MySqlServerConnection" accepts only one parameter, if so, it should work without problems.

    
answered by 05.12.2018 в 23:49
0

They are two different things: when there is a parameter the correct thing would be to use a prepared query, when there are no parameters, the correct thing would be to use query simply. You can do it with the same method or create a method for each thing.

Let's look at the two possibilities:

Using the same method

Because PHP allows you to use default argument values , you can write a method that accepts or does not accept certain arguments. In this case, executeQuery may or may not receive a second argument $params . Then inside you handle the logic for when you receive arguments or not.

public function executeQuery($query,$params=NULL){
    if ( $params ) {
        /*Si se enviaron parámetros para el execute usamos esta forma*/
        $stmt=$connection->prepare($query);
        $stmt->execute($params);
        //obtener $result
    } else {
        /*Si no se enviaron parámetros usamos esta*/
        $data=$connection->query($query);
        //obtener $result
    }
    return $result;
}

In this case, when you are going to use query you only have to pass the first parameter in the call, that is, instead of this:

$result = $connection->executeQuery($query, array($folio));

You would do this:

$result = $connection->executeQuery($query);

The method would determine that $params is NULL and would execute the query without criteria.

Using different methods

It would be to write a method with prepare and another with query and call each one as appropriate.

The first one you already have, the one that you say works. The second you would have to write it without parameters and without prepare , execute ... only with query :

public function executeQueryWithOutParams($query){
        $data=$connection->query($query);
        //obtener $result
        return $result;
}

When you need queries without parameters, you would call this method.

    
answered by 06.12.2018 в 01:45