i try to get data from specific timestamp into database DT.
i try this but not work
code :
Route::get('/l', function(){
$day = date('Y-m-d H:i:s', strtotime($_GET['day']));
$users = DB::select('select * from DT where (`timestamp` = "'.$day.'")' );
return $users;
})->middleware('auth:api');
in postman i put into params : day 2020-07-01
Any help?
Solved !
Route::get('/l', function(){
$day = date('Y-m-d ', strtotime($_GET['day']));
$users = DB::select('select * from DT where (`timestamp` like "'.$day.'%")' );
})->middleware('auth:api');
Related
There any one know how to implementation my sql code using data record
SELECT *
FROM `jadwal`
WHERE YEAR(tgl) = YEAR(NOW())
AND MONTH(tgl) = MONTH(NOW())
AND DAY(tgl) = DAY(NOW())
Thanks in advance
You can do it as follows -
$where = array('YEAR(tgl)' => YEAR(NOW()),
'MONTH(tgl)' => MONTH(NOW()),
'DAY(tgl)' => DAY(NOW())
);
$this->db->select('*');
$this->db->where($where);
$query = $this->db->get('jadwal');
$res1 = $query->result(); // as object
$res2 = $query->result_array(); // as array
try and let me know.
I started my project March last year and have almost got it right.
Trying to get data from mysql and put it in highcharts.
This is my query
<?php
$con = mysqli_connect("localhost","root","root","manortsc_test");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$sth = mysqli_query($con,"
SELECT DateTime,max(T)
FROM alldata
WHERE DATE(DateTime) = CURDATE() - INTERVAL 1 DAY
GROUP BY hour(DateTime)
"
);
$rows = array();
$rows['name'] = 'Outside';
while($r = mysqli_fetch_array($sth)) {
$rows['data'][] = $r['max(T)'];
}
$result = array();
array_push($result,$rows);
print json_encode($result, JSON_NUMERIC_CHECK);
mysqli_close($con);
?>
The json output is missing the date and time
[{"name":"Outside","data":[17.5,16.3,15.6,15.1,14.4,14,14.1,16,18.5,21.7,24.1,26.9,28.3,29.6,30.6,31.1,31.8]}]
The graph shows okay (except datetime on x axis) and I cannot figure how to fix it. I have tried every way except the correct way. Any help would be appreciated.
Changed the query to this and now it works.
Thanks wergeld and Yuri for the assistance.
$sth = mysqli_query($con,"
SELECT DateTime,max(T)
FROM davisvp
WHERE DATE(DateTime) = CURDATE()
GROUP BY hour(DateTime)
"
);
$result = array();
$result['name'] = 'temperature';
while($row = mysqli_fetch_array($sth))
{
$date = strtotime($row['DateTime']);
$maxt = 1 * $row['max(T)'];
$result1 = array();
array_push($result1,$date);
array_push($result1,$maxt);
$result['data'][] = $result1;
}
echo json_encode($result, JSON_NUMERIC_CHECK);
I'm currently using Zend Framework 2 and a query with date ranges to obtain data out of a MySQL DB, and I came across the between clause that was previously not available in ZF1.
However, my code which looks something like this is not working correctly:
$dateStart = '2012-12-20';
$dateEnd = '2012-12-31';
$sql = new Sql($_db);
$select = $sql->select()
->from(array("t" => $table))
->columns(array("col1" => "col_as_1", "col2" => "col_as_2"));
$select->where->between("date", $dateStart, $dateEnd);
$stmt = $sql->prepareStatementForSqlObject($select);
$result = $stmt->execute()->getResource()->fetchAll(\PDO::FETCH_ASSOC);
Apparently the between clause is not inclusive, I can only get results until 2012-12-30, is there a way to make it inclusive? I've been taking a look at the ZF2 docs but they are not very helpful and running the same query on MySQL query browser returns all of the data I need.
So you can try lessThanOrEqualTo and greaterThanOrEqualTo.
Between doesn't seem to provide this functionality: between($identifier, $minValue, $maxValue)
If you trace out your query with $select->__toString() you can see the query as string.
I don't have ZF2 on my computer but I could imagine that between in ZF2 will output date > '2012-12-20' AND date < '2012-12-31'.
NOTE THIS : WHEN USING between on Mysql
date_column_name between 'startDate' AND 'endDate'
NOTE : you should want to insert +1 date to endDate . Because of when you insert 2015-05-18 date to endDate.you can not get data of 2015-05-18.So you need to plus one date to endDate.
You can do it using this
$plusToDate = date('Y-m-d H:i:s', strtotime($toDate . ' + 1 day'));
The BETWEEN should be inclusive, are you sure there are no hours, minutes and seconds after the date, that would cause it not to select dates on 2012-12-31 since 2012-12-31 00:00:01 would technically be > 2012-12-31
Format must be same, use mysql DATE function
$select->where->between("DATE(date)", DATE('.$dateStart.'), DATE('.$dateEnd.'));
$from_date = date('Y-m-d', strtotime($AppCleaner->from_date ));
$to_date = date('Y-m-d', strtotime($AppCleaner->to_date ));
$select->where->between('appointment_date', $from_date . ' 00:00:00', $to_date . ' 23:59:59');
also, Use the between clause as below:
$sql = new Sql($this->adapter);
$select = $sql->select();
$select->from('app_posts');
$select->where->NEST->between( 'id', 30,40);
$select->group('app_posts.id');
// echo $select->getSqlString($this->adapter->getPlatform());
// exit;
$statement = $sql->prepareStatementForSqlObject($select);
$result = $statement->execute();
$resultSet = new ResultSet();
$resultSet->initialize($result);
$posts = $resultSet->buffer()->toArray();
return $resultSet;
Try this:
//I have a static function to make conversion Data Format
public static function convertBrazilianDate2MySQLDatabase($dataBrazil) {
$array = explode("/", $dataBrazil);
$array = array_reverse($array);
$str = implode($array, "/");
return date("Y-m-d", strtotime($str));
}
//In My Service I built my sentence
$dtStart = \Estrutura\Helpers\Data::convertBrazilianDate2MySQLDatabase($dt_start) . ' 00:00:01';
$dtEnd = \Estrutura\Helpers\Data::convertBrazilianDate2MySQLDatabase($dt_end) . ' 23:59:59';
$select->where->between('field name in table', $dtStart, $dtEnd);
[...]
I am new to Doctrine ORM or any ORM
$em = Zend_Registry::getInstance ()->entitymanager;
$p = $em->createQuery ( "
SELECT u
FROM Teon_Model_User u
WHERE u.app_auth IN (:app_auth)" );
$p->setParameter ( 'app_auth', $app_auth );
$array = $p->getArrayResult();
$customer_id = $array[0]['customer_id'];
$p = $em->createQuery ( "
SELECT p
FROM Teon_Model_Purchase p
WHERE p.customer IN (:customer_id)" );
$p->setParameter ( 'customer_id', $customer_id );
$array = $p->getArrayResult();
$purchase_id = $array[0]['id'];
$p = $em->createQuery ( "
SELECT pm
FROM Teon_Model_PurchaseManual pm
WHERE pm.purchase_id IN (:purchase_id)" );
$p->setParameter ( 'purchase_id', $purchase_id );
$array = $p->getArrayResult();
$m_id = $array[0]['manual_id'];
Can you simplify this query, it looks so stupid, I am using Doctrine in zend framework
this query is to authenticate the user whether he has manual_id in his purchases by supplying a authentication code..
Here's the 2 simple way i could think of to do this:
<?php
$em = Zend_Registry::getInstance()->entitymanager;
// 1st way
$user = $em->getRepository('Teon_Model_User')->findOneByAppAuth($app_auth);
$user->getCustomerId();
// 2nd way
$user = $em->getRepository('Teon_Model_User')->findOneBy(array(
'app_auth' => $app_auth,
));
$user->getCustomerId();
i need to create a function that will display the articles of the current date only.
Here is what i have created:
function lastnews () {
$id = mysql_real_escape_string ($id);
$date = date('d');
$sql = 'SELECT * FROM posts WHERE post_status = "publish" AND post_date = "$date" ORDER BY post_date DESC LIMIT 3';
$res = mysql_query($sql) or die (mysql_error());
if (mysql_num_rows($res) !=0):
while ($row = mysql_fetch_assoc($res)) {
$title = $row['post_title'];
echo '<li>'.$title.'</li>';
}
endif;
} // end
But this is not working. the formt of date in database is :
Y-m-d H:i
Thank you for reading this
You need to specify the entire date (date('Y-m-d')) and the query should say AND post_date > '$date' because it includes a time. You can also say AND post_date > CURRENT_DATE.
Change
$date = date('d');
To:
$date = date('Y-m-d H:i');