im8kers Posted August 13, 2007 Share Posted August 13, 2007 Hello, I have been searching everywhere to figure this out but haven't found anything. So either it's stupid simple or I'm going about it the wrong way. Here is my sql code: SELECT p.*, c.bagsrecd, c.recddate, c.locationid FROM ninlf_received AS c INNER JOIN ninlf_recipient AS p ON c.recipientid = p.recipientid WHERE c.recddate >= '$_POST["start"]' AND c.recddate <= '$_POST["end"]' I need to filter the data by the variables from a previous page post. I am using MySQL 5.0 and will create this as a view. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/ Share on other sites More sharing options...
Illusion Posted August 14, 2007 Share Posted August 14, 2007 make sure that c.recddate ,$_POST["start"] and $_POST["end"] all are having the same format. Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-323545 Share on other sites More sharing options...
im8kers Posted August 14, 2007 Author Share Posted August 14, 2007 All formats are the same. I did a query and hard coded dates in their place and it ran great. I just can't seem to get the dates to be from the variables!?! Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-323582 Share on other sites More sharing options...
Illusion Posted August 14, 2007 Share Posted August 14, 2007 the ntry WHERE c.recddate >= '$_POST[start]' AND c.recddate <= '$_POST[end]' or WHERE c.recddate >= '{$_POST['start']}' AND c.recddate <= '{$_POST['end']}' Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-323595 Share on other sites More sharing options...
im8kers Posted August 14, 2007 Author Share Posted August 14, 2007 Niether one worked. The first one nothing showed in the result and the second gave me an #1064 error. Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-323666 Share on other sites More sharing options...
Illusion Posted August 14, 2007 Share Posted August 14, 2007 then try something like this $query="SELECT p.*, c.bagsrecd, c.recddate, c.locationid FROM ninlf_received AS c INNER JOIN ninlf_recipient AS p ON c.recipientid = p.recipientid WHERE c.recddate >= ".$_POST['start']."AND c.recddate <= ".$_POST['end']; before running the query first echo ur query like echo $query; and then execute if ur varibles are interpreted. Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-323675 Share on other sites More sharing options...
im8kers Posted August 14, 2007 Author Share Posted August 14, 2007 After a couple tweeks the query echoed the variables correctly in the page. I created a view and the it still won't grab the variable from the page into the view. ??? Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-323706 Share on other sites More sharing options...
fenway Posted August 20, 2007 Share Posted August 20, 2007 I don't see the view code anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-329209 Share on other sites More sharing options...
im8kers Posted August 28, 2007 Author Share Posted August 28, 2007 Here is the code again. Again I'm attempting to have this code run from the mysql database and not from the php page. SELECT p.*, c.bagsrecd, c.recddate, c.locationid FROM ninlf_received AS c INNER JOIN ninlf_recipient AS p ON c.recipientid = p.recipientid WHERE c.recddate >= '$_POST["start"]' AND c.recddate <= '$_POST["end"]' Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-336444 Share on other sites More sharing options...
fenway Posted August 28, 2007 Share Posted August 28, 2007 How do you intend to use $POST from the mysql database? Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-336590 Share on other sites More sharing options...
im8kers Posted September 5, 2007 Author Share Posted September 5, 2007 I guess that is my question. It all works from the page source in the php query, but that's not where I need it. Do you have any recommendations how I can make the mysql source "look or refer" to the $POST variable? Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-342139 Share on other sites More sharing options...
fenway Posted September 6, 2007 Share Posted September 6, 2007 I guess that is my question. It all works from the page source in the php query, but that's not where I need it. Do you have any recommendations how I can make the mysql source "look or refer" to the $POST variable? I don't really know what this means. Quote Link to comment https://forums.phpfreaks.com/topic/64686-using-date-variable-from-form-in-where-statement/#findComment-343330 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.