MonoConmab
-
Posts
2 -
Joined
-
Last visited
Posts posted by MonoConmab
-
-
I'm designing a rental service and am working on a query to see if an item is available in a certain date range
So far my query is as follows
$q = "SELECT SUM(quantity) AS total FROM orders, order_details WHERE orders.order_id = order_details.order_id"; $q .= " AND equip_ID =".$item['id']; $q .= " AND 'start_date' > '".$start_date."'"; $result = $db->query($q); $row = mysqli_fetch_assoc($result); $sum = $row['total'];
Say for instance $start_date = 2021-03-03 the output of $q would be
SELECT SUM(quantity) AS total FROM orders, order_details WHERE orders.order_id = order_details.order_id AND equip_ID =12 AND 'start_date' > '2021-03-03'
This does not work but if i manually insert $q into my mysql database it works.
It comes up with the error shown below when I submit it from php, but not when I do directly into mysql
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 ''start_date' > '2021-03-03'' at line 1
When I try hard-coding a date in I get the same error. Whats confusing is it works when I directly put it into mysql
MySql query to compare dates php
in MySQL Help
Posted · Edited by MonoConmab
Taking the Column Names out of the quotes doesn't work either
Also I'm new to PHP, how would I format this in PDO?