PHP function select 2 values

4

Good!

I am creating functions in PHP with the aim of returning the difference between the date TIMESTAMP of the database and today's date, and for this I have created two functions:

function getRegistos()
{
    $query = "SELECT *, DATEDIFF(NOW(),dataDeEntrada) as diferenca FROM 'equipamentos' WHERE 1";
    $this->connect();
    $res = $this->execute($query);
    $this->disconnect();
    return $res;
}

function getData()
{
    $query = "SELECT (dataDeEntrada2), DATEDIFF(NOW(),dataDeEntrada2) as diferencaTotais FROM 'equipamentos' WHERE 1";
    $this->connect();
    $res = $this->execute($query);
    $this->disconnect();
    return $res;
}

% is used to fetch registrations and days elapsed, and getRegistos() is only used to get the total days since the product was registered (because when the administrator updates a product the column DateEntry returns to 0) .

I do not know if it's possible to join the two or call them differently ...

include_once('DataAccess.php');
            $da = new DataAccess();
            $res = $da->getRegistos();
            $res1 = $da->getData();
            while($row = mysqli_fetch_object($res)){ ... }

But only returns getData() . I also tried to do another while but this time with getRegistos() which is the value returned by $res1 but nothing done. I'm new to PHP and I think I'm just complicating.

    
asked by anonymous 26.01.2016 / 13:21

1 answer

2

Resolved

The only thing I changed was calling functions.

Well, I called them like this:

$id = $_SESSION['id'];
include_once('DataAccess.php');
$da = new DataAccess();
$res = $da->getEquipamento($id);
while($row = mysqli_fetch_object($res)){ ... }

And the only thing missing was this:

$res1 = $da->getData();
$row1 = mysqli_fetch_object($res1);

That is, it looks like this:

$id = $_SESSION['id'];
include_once('DataAccess.php');
$da = new DataAccess();
$res = $da->getEquipamento($id);
$res1 = $da->getData();
while($row = mysqli_fetch_object($res)){
$row1 = mysqli_fetch_object($res1);
... 
}
    
27.01.2016 / 19:09