CURDATE gives error - mysql

I have an INSERT statement,
$stmt = $mysqli->prepare("INSERT INTO numbertable (numbers, numdate, salesperson, color) VALUES (?, NOW(), ?, ?)");
My SELECT statement looks like this:
$result = $mysqli->query("SELECT COUNT FROM numbertable WHERE DATE(numdate) == CURDATE()");
When I run my select statement, I get the following error. Does anybody know what that could be?
SELECT COUNT FROM numbertable WHERE DATE(numdate) == CURDATE()
LIMIT 0, 30
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '== CURDATE()
LIMIT 0, 30' at line 1

in mySQL you need = as equal sign, not ==. should be:
SELECT COUNT FROM numbertable WHERE DATE(numdate) = CURDATE()

Related

Want to use this but giving error in syntax help me to fix permanent in Query Builder Codeigniter

SELECT installation
FROM `id`
WHERE `outlet_id` = '9'
AND `status` = '1'
GROUP BY `page_rank` `asc`
ORDER BY `page_rank=0`
LIMIT -1, 1
Page Rank=0 gives error
You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near 'asc ORDER BY page_rank=0 LIMIT -1, 1' at line 5
Query using codeigniter query builder class -
$this->db->select('installation') // column name
$this->db->from('id'); // table name
$this->db->where('outlet_id', 9); // condition
$this->db->where('status', 1);
$this->db->group_by('page_rank');
$this->db->order_by('page_rank', 'ASC');
$this->db->limit(1, 0); // will show 1 result starting from 0 ie first result
$query = $this->db->get()->result();
return $query;
Produces
SELECT installation
FROM `id`
WHERE `outlet_id` = 9
AND `status` = 1
GROUP BY `page_rank`
ORDER BY `page_rank` ASC
LIMIT 0, 1
See if it solves your issue.

Compare database timestamp value with today's date and get the result in codeigniter

HI guys i am trying to get the result from db where my table column displaytime is equal to today's date.
So i am trying to check that condition by using where. But i don't know hat is the problem it showing query is wrong
Here is my model:
function getDashboardContent() {
$today = date('Y-m-d H-i');
$this->db->select('cd.details,g.displaytime');
$this->db->where('cd.typeofinfo', 2);
$this->db->where("DATE_FORMAT(g.displaytime,'%Y-%m-%d %H-%i')", $today );
$this->db->from('contentdetails cd');
$this->db->join('content c', 'c.id = cd.contentid');
$this->db->join('group_content gc', 'gc.contentid = c.id');
$this->db->join('groups g', 'g.id = gc.groupid');
$this->db->order_by('cd.id',"DESC");
$this->db->limit('1');
$query = $this->db->get();
print_r($query);
exit;
return $query->result();
}
Here is my error:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''2018-07-27 12-02' ORDER BY `cd`.`id` DESC LIMIT 1' at line 7
SELECT `cd`.`details`, `g`.`displaytime` FROM `contentdetails` `cd` JOIN `content` `c` ON `c`.`id` = `cd`.`contentid` JOIN `group_content` `gc` ON `gc`.`contentid` = `c`.`id` JOIN `groups` `g` ON `g`.`id` = `gc`.`groupid` WHERE `cd`.`typeofinfo` = 2 AND DATE_FORMAT(g.displaytime,'%Y-%m-%d %H-%i') '2018-07-27 12-02' ORDER BY `cd`.`id` DESC LIMIT 1
Can anyone help me what is the exact problem and what mistake i have done
Thanks in advance.
Why don't you change datetime to timestamp and then compare like this
$this->db->where("TO_SECONDS(g.displaytime)", strtotime($today) );
i have solve my problem by changing this line
$this->db->where("DATE_FORMAT(g.displaytime,'%Y-%m-%d %H-%i')!=", "$today" );
TO
$this->db->where("DATE_FORMAT(g.displaytime,'%Y-%m-%d %H-%i') = '" . $today . "'");

MySQL : error in your SQL syntax | LIMIT 0, 25

I dont understand this error, guys please help me. why I am getting this error..
Is there something wrong in my query?
this is the error..
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near 'LIMIT 0, 25' at line 7
and this is my query:
SELECT
equivalent
FROM
tb_student_record
INNER JOIN
tb_student ON tb_student_record.stud_id = tb_student.stud_id
WHERE
tb_student_record.instructor_id = 'INST-20131296'
AND tb_student_record.criteria_id = '1'
AND tb_student_record.class_record_id = '1'
AND (CONCAT(stud_fname, ' ', stud_lname) = 'Jeffrey Oliveras'
AND tb_student_record.term = 'Prelim'
you are missing closing paranthesis at concat function
SELECT equivalent FROM tb_student_record INNER JOIN tb_student ON tb_student_record.stud_id=tb_student.stud_id
WHERE tb_student_record.instructor_id = 'INST-20131296'
AND tb_student_record.criteria_id = '1'
AND tb_student_record.class_record_id = '1'
AND (CONCAT(stud_fname, ' ', stud_lname) = 'Jeffrey Oliveras' )
AND tb_student_record.term = 'Prelim'
It seems that your query have problem at the end:

Why is this a SQL syntax error?

I have this query in Perl:
my $pkg="%";
my $sql = "SELECT pid, CAST(pid as UNSIGNED) AS l FROM xmld ORDER BY l WHERE pkg LIKE ?";
my $files_ref = $dbh->selectcol_arrayref($sql, undef, $pkg);
It crashes with:
DBD::mysql::db selectcol_arrayref failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE pkg LIKE '%'' at line 1 at ...
I have been looking at this statement for hours, tried various things, but no luck.
Where is that extra single quote coming from and how do I get rid of it?
order by goes after the where:
SELECT pid, CAST(pid as UNSIGNED) AS l
FROM xmld
WHERE pkg LIKE ?
ORDER BY l;

SELECT error querying

What could be wrong with this line:
'$query = "SELECT * FROM messages WHERE (rlat => '".$latmin."' AND rlat <= '".$latmax."') AND (rlon >= '".$lonmin."' AND rlon <= '".$lonmax."')";'
Error: Error in query: SELECT * FROM messages WHERE (r_lat =>
'55.4655951769' AND r_lat <= '55.496987423') AND (r_lon >=
'25.5338700398' AND r_lon <= '25.5989507602'). You have an error in
your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near '=> '55.4655951769'
AND r_lat <= '55.496987423') AND (r_lon >= '25.5338700398' AN' at line
1...
Thanks!
=> isn't a known operator. If you want the greater than or equal comparison operator, then you are after >=.
Incidentally, you might find that your query can be written more concisely with the BETWEEN ... AND ... operator:
SELECT *
FROM messages
WHERE rlat BETWEEN $latmin AND $latmax
AND rlon BETWEEN $lonmin AND $lonmax
You should also investigate passing variables into your SQL by way of parameters to prepared statements.