4
Good!
I am creating functions in PHP in order to return the difference between the date TIMESTAMP
of the database and today’s date, and for that I 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;
}
To getRegistos()
serves to retrieve the records and the days elapsed and the getData()
is only used to get the total days since the product was registered ( because when the administrator updates a product to the outdated column it returns to 0 ).
I don’t know if it’s possible to put the two together 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 back to me getRegistos()
. I also tried to do another while but this time with $res1
which is the value returned by getData()
but nothing done.
I’m new to PHP and I believe I’m just complicating.
I think you’re complicating things. See: http://sqlfiddle.com/#! 9/a677a/1
– Marconi
The link you sent doesn’t work. In the Equipment table I have the following columns: ID, id_user, name, type, status, dateDentry, dateDentry 2, brand, model, symptom, budget
– Bruny
It works, just wait a little. At least for me it works.
– Marconi
OK today I managed to open. That’s what I did. But I wanted to keep 2 differences. One for the days elapsed and another for the Total days because one will be reset and the other is not why I have 2 datesEntrate in the database.
– Bruny
I get it, on Monday you can use
SELECT SUM(DATEDIFF(NOW(), d2)) AS TOTAL FROM t;
According to my SQLFIDDLE.– Marconi
Exactly, but that would mean creating another function.
– Bruny
But that’s what I’ve done. Now the problem is to call both. As you can see I used a while to show all the equipment table information. Now I need another just to show the total days.
– Bruny
I understand, sorry for the misunderstanding. But call the Getregistros and do not Call the Getdata?
– Marconi